本文整理汇总了Java中java.util.GregorianCalendar.getTimeInMillis方法的典型用法代码示例。如果您正苦于以下问题:Java GregorianCalendar.getTimeInMillis方法的具体用法?Java GregorianCalendar.getTimeInMillis怎么用?Java GregorianCalendar.getTimeInMillis使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.GregorianCalendar
的用法示例。
在下文中一共展示了GregorianCalendar.getTimeInMillis方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getYearlessMillis
import java.util.GregorianCalendar; //导入方法依赖的package包/类
/**
* Antaa millisekuntiajan ilman vuositietoa. Alusta poistetaan nollat jos niitä on.<br/>
* <b>Poistettu käytöstä, koska testatessa ilmeni ongelmia. Parempi käyttää vain timestampia 'as is'.</b><br/>
* (Katsotaan ehkä joskus myöhemmin, mikäli käytössä olisi mitään järkeä.)
*
* @param millis
* Millisekuntiaika, jota käytetään pohjana sekvenssiarvon generoimiseen
* @return Millisekunnit ilman vuosia
* @deprecated
*/
@Deprecated
protected String getYearlessMillis(long millis) {
GregorianCalendar gregZero = new GregorianCalendar();
gregZero.setTimeInMillis(millis);
gregZero.set(Calendar.MONTH, 0);
gregZero.set(Calendar.DAY_OF_MONTH, 1);
gregZero.set(Calendar.HOUR_OF_DAY, 0);
gregZero.set(Calendar.MINUTE, 0);
gregZero.set(Calendar.SECOND, 0);
gregZero.set(Calendar.MILLISECOND, 0);
long alteredMillis = gregZero.getTimeInMillis();
return Long.toString(millis - alteredMillis).substring(0, 3);
}
示例2: getCountDaysBetweenDates
import java.util.GregorianCalendar; //导入方法依赖的package包/类
public static Integer getCountDaysBetweenDates(Date d1, Date d2) {
GregorianCalendar dataInicio = new GregorianCalendar();
dataInicio.setTime(d1);
dataInicio.set(Calendar.AM_PM, Calendar.AM);
dataInicio.set(Calendar.HOUR, 0);
dataInicio.set(Calendar.MINUTE, 0);
dataInicio.set(Calendar.SECOND, 0);
dataInicio.set(Calendar.MILLISECOND, 0);
GregorianCalendar dataFim = new GregorianCalendar();
dataFim.setTime(d2);
dataFim.set(Calendar.AM_PM, Calendar.AM);
dataFim.set(Calendar.HOUR, 0);
dataFim.set(Calendar.MINUTE, 0);
dataFim.set(Calendar.SECOND, 0);
dataFim.set(Calendar.MILLISECOND, 0);
if (dataFim.get(Calendar.YEAR) > dataInicio.get(Calendar.DAY_OF_YEAR)) {
long diffMillis = dataFim.getTimeInMillis() - dataInicio.getTimeInMillis();
long diffDays = diffMillis / (24 * 60 * 60 * 1000);
return Long.valueOf(diffDays).intValue();
}
return 0;
}
示例3: scheduleNextLindviorDate
import java.util.GregorianCalendar; //导入方法依赖的package包/类
protected long scheduleNextLindviorDate()
{
final GregorianCalendar date = new GregorianCalendar();
date.set(Calendar.MINUTE, RESET_MIN);
date.set(Calendar.HOUR_OF_DAY, RESET_HOUR);
if (System.currentTimeMillis() >= date.getTimeInMillis())
{
date.add(Calendar.DAY_OF_WEEK, 1);
}
final int dayOfWeek = date.get(Calendar.DAY_OF_WEEK);
if (dayOfWeek <= RESET_DAY_1)
{
date.add(Calendar.DAY_OF_WEEK, RESET_DAY_1 - dayOfWeek);
}
else if (dayOfWeek <= RESET_DAY_2)
{
date.add(Calendar.DAY_OF_WEEK, RESET_DAY_2 - dayOfWeek);
}
else
{
date.add(Calendar.DAY_OF_WEEK, 1 + RESET_DAY_1);
}
return date.getTimeInMillis() - System.currentTimeMillis();
}
示例4: testBug7686
import java.util.GregorianCalendar; //导入方法依赖的package包/类
public void testBug7686() throws SQLException {
String tableName = "testBug7686";
createTable(tableName, "(id1 int(10) unsigned NOT NULL, id2 DATETIME, field1 varchar(128) NOT NULL default '', PRIMARY KEY (id1, id2))", "InnoDB;");
this.stmt.executeUpdate("insert into " + tableName + " (id1, id2, field1) values (1, '2005-01-05 13:59:20', 'foo')");
String sQuery = " SELECT * FROM " + tableName + " WHERE id1 = ? AND id2 = ?";
this.pstmt = this.conn.prepareStatement(sQuery, ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
this.conn.setAutoCommit(false);
this.pstmt.setInt(1, 1);
GregorianCalendar cal = new GregorianCalendar();
cal.clear();
cal.set(2005, 00, 05, 13, 59, 20);
Timestamp jan5before2pm = null;
jan5before2pm = new java.sql.Timestamp(cal.getTimeInMillis());
this.pstmt.setTimestamp(2, jan5before2pm);
this.rs = this.pstmt.executeQuery();
assertTrue(this.rs.next());
this.rs.absolute(1);
this.rs.updateString("field1", "bar");
this.rs.updateRow();
this.conn.commit();
this.conn.setAutoCommit(true);
}
示例5: set
import java.util.GregorianCalendar; //导入方法依赖的package包/类
public void set( GregorianCalendar base, GregorianCalendar now ){
int offset;
offset = (int)(now.getTimeInMillis() - base.getTimeInMillis()) / wheelConfig.getWheelSize(); // convert based on wheel resolution
cycles = offset / wheelConfig.getWheelSize();
index = offset % wheelConfig.getWheelSize();
}
示例6: DateGenerator
import java.util.GregorianCalendar; //导入方法依赖的package包/类
public DateGenerator(GregorianCalendar from, Integer toSpanInDays, Long seed)
{
this.from = from.getTimeInMillis();
this.to = this.from + oneDayInMillis*toSpanInDays;
ranGen = new Random(seed);
}
示例7: main
import java.util.GregorianCalendar; //导入方法依赖的package包/类
/**
* Some test code.
*
* @param args ignored.
*/
public static void main(String[] args) {
GregorianCalendar c0 = new GregorianCalendar(2006, 10, 1, 0, 0, 0);
GregorianCalendar c1 = new GregorianCalendar(2006, 10, 1, 11, 37, 43);
c1.set(Calendar.MILLISECOND, 123);
System.out.println("Default: ");
RelativeDateFormat rdf = new RelativeDateFormat(c0.getTimeInMillis());
System.out.println(rdf.format(c1.getTime()));
System.out.println();
System.out.println("Hide milliseconds: ");
rdf.setSecondFormatter(new DecimalFormat("0"));
System.out.println(rdf.format(c1.getTime()));
System.out.println();
System.out.println("Show zero day output: ");
rdf.setShowZeroDays(true);
System.out.println(rdf.format(c1.getTime()));
System.out.println();
System.out.println("Alternative suffixes: ");
rdf.setShowZeroDays(false);
rdf.setDaySuffix(":");
rdf.setHourSuffix(":");
rdf.setMinuteSuffix(":");
rdf.setSecondSuffix("");
System.out.println(rdf.format(c1.getTime()));
System.out.println();
}
示例8: dateToJulian
import java.util.GregorianCalendar; //导入方法依赖的package包/类
public static long dateToJulian(Date date) {
GregorianCalendar calendarDate = new GregorianCalendar();
calendarDate.setTime(date);
Calendar calendarBegin = new GregorianCalendar(1, GregorianCalendar.JANUARY, 1);
long millisecondsDate = calendarDate.getTimeInMillis();
long millisecondsBegin = calendarBegin.getTimeInMillis();
long diff = millisecondsDate - millisecondsBegin;
long diffDays = diff / (24 * 60 * 60 * 1000) - 1;
return diffDays;
}
示例9: randomDateInMillis
import java.util.GregorianCalendar; //导入方法依赖的package包/类
public Long randomDateInMillis(Long from, Long to)
{
long date = (long)(ranGen.nextDouble()*(to-from)+from);
GregorianCalendar gc = new GregorianCalendar();
gc.setTime(new Date(date));
return gc.getTimeInMillis();
}
示例10: PostLimitOrder
import java.util.GregorianCalendar; //导入方法依赖的package包/类
public void PostLimitOrder( TTradeRequest tradeRequest ){
TradeType eTradeType;
double CurrentPrice = -1.0;
TTickerEntry pNewEntry = new TTickerEntry();
eTradeType = ConvertTradeTypeIdToEnum(tradeRequest.trade_type_id.toCharArray());
pNewEntry.price_quote = tradeRequest.price_quote;
pNewEntry.symbol = new String(tradeRequest.symbol);
pNewEntry.trade_qty = LIMIT_TRIGGER_TRADE_QTY;
CurrentPrice = priceBoard.getCurrentPrice( tradeRequest.symbol ).getDollars();
if((( eTradeType == TradeType.eLimitBuy || eTradeType == TradeType.eStopLoss ) &&
CurrentPrice <= tradeRequest.price_quote )
||
(( eTradeType == TradeType.eLimitSell ) &&
CurrentPrice >= tradeRequest.price_quote )){
pNewEntry.price_quote = CurrentPrice;
limitOrderTimers.processExpiredTimers();
inTheMoneyLimitOrderQ.add(pNewEntry);
}
else{
pNewEntry.price_quote = tradeRequest.price_quote;
double TriggerTimeDelay;
GregorianCalendar currGreTime = new GregorianCalendar();
GregorianCalendar baseGreTime = new GregorianCalendar();
currGreTime.setTime(currentTime);
baseGreTime.setTime(baseTime);
double fCurrentTime = currGreTime.getTimeInMillis() - baseGreTime.getTimeInMillis();
//TODO the third para, compare to c++
TriggerTimeDelay = priceBoard.getSubmissionTime(pNewEntry.symbol, fCurrentTime, new EGenMoney(pNewEntry.price_quote), eTradeType) - fCurrentTime;
limitOrderTimers.startTimer( TriggerTimeDelay);
}
}
示例11: marshal
import java.util.GregorianCalendar; //导入方法依赖的package包/类
@Override
public void marshal(final Object source, final HierarchicalStreamWriter writer, final MarshallingContext context) {
final GregorianCalendar calendar = (GregorianCalendar)source;
ExtendedHierarchicalStreamWriterHelper.startNode(writer, "time", long.class);
final long timeInMillis = calendar.getTimeInMillis();
writer.setValue(String.valueOf(timeInMillis));
writer.endNode();
ExtendedHierarchicalStreamWriterHelper.startNode(writer, "timezone", String.class);
writer.setValue(calendar.getTimeZone().getID());
writer.endNode();
}
示例12: getJulianDay
import java.util.GregorianCalendar; //导入方法依赖的package包/类
/**
* Get julian day by unix timestamp
* @param mills
* @return
*/
public static double getJulianDay(long mills) {
GregorianCalendar calendar = new GregorianCalendar();
calendar.setTimeInMillis(mills);
int year;
int month;
float day;
int b = 0;
double fraction;
fraction = (calendar.get(Calendar.HOUR_OF_DAY) / 0.000024 + calendar.get(Calendar.MINUTE) / 0.001440);
DecimalFormat decimalFormat = new DecimalFormat("0");
day = calendar.get(Calendar.DAY_OF_MONTH);
day = Float.parseFloat(decimalFormat.format(day) + "." + decimalFormat.format(Math.round(fraction)));
year = calendar.get(Calendar.YEAR);
month = calendar.get(Calendar.MONTH) + 1;
if (month < 3) {
year--;
month += 12;
}
if (calendar.getTimeInMillis() - calendar.getGregorianChange().getTime() > 0) {
int a = year / 100;
b = 2 - a + a / 4;
}
double julianDay;
julianDay = Math.floor(365.25 * year) + Math.floor(30.6001 * (month + 1)) + day + 1720994.5 + b;
return julianDay;
}
示例13: generateRandomIatDateInPast
import java.util.GregorianCalendar; //导入方法依赖的package包/类
public static Date generateRandomIatDateInPast() {
GregorianCalendar gc = new GregorianCalendar();
int year = randBetween(1900, 2010);
gc.set(gc.YEAR, year);
int dayOfYear = randBetween(1, gc.getActualMaximum(gc.DAY_OF_YEAR));
gc.set(gc.DAY_OF_YEAR, dayOfYear);
return new Date(gc.getTimeInMillis());
}
示例14: timeSpanToString
import java.util.GregorianCalendar; //导入方法依赖的package包/类
public static final String timeSpanToString(GregorianCalendar startGc, GregorianCalendar stopGc) {
long millis = stopGc.getTimeInMillis() - startGc.getTimeInMillis();
return millis / 60000 + " minutes";
}
示例15: getDate
import java.util.GregorianCalendar; //导入方法依赖的package包/类
public static LogicalExpression getDate(GregorianCalendar date) {
return new org.apache.drill.common.expression.ValueExpressions.DateExpression(date.getTimeInMillis());
}