本文整理了Java中java.util.Calendar.getTimeInMillis()
方法的一些代码示例,展示了Calendar.getTimeInMillis()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Calendar.getTimeInMillis()
方法的具体详情如下:
包路径:java.util.Calendar
类名称:Calendar
方法名:getTimeInMillis
[英]Returns the time represented by this Calendar, recomputing the time from its fields if necessary.
[中]返回此日历表示的时间,必要时从其字段重新计算时间。
代码示例来源:origin: apache/incubator-dubbo
/**
* between 2:00 am to 6:00 am, the time is random.
*
* @return
*/
long calculateStartTime() {
Calendar calendar = Calendar.getInstance();
long nowMill = calendar.getTimeInMillis();
calendar.set(Calendar.HOUR_OF_DAY, 0);
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.SECOND, 0);
calendar.set(Calendar.MILLISECOND, 0);
long subtract = calendar.getTimeInMillis() + ONE_DAY_IN_MIll - nowMill;
return subtract + (FOUR_HOURS_IN_MIll / 2) + ThreadLocalRandom.current().nextInt(FOUR_HOURS_IN_MIll);
}
代码示例来源:origin: apache/rocketmq
private synchronized static void setStartTime(long millis) {
Calendar cal = Calendar.getInstance();
cal.setTimeInMillis(millis);
cal.set(Calendar.DAY_OF_MONTH, 1);
cal.set(Calendar.HOUR_OF_DAY, 0);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MILLISECOND, 0);
startTime = cal.getTimeInMillis();
cal.add(Calendar.MONTH, 1);
nextStartTime = cal.getTimeInMillis();
}
代码示例来源:origin: stackoverflow.com
Calendar cal = Calendar.getInstance();
Intent intent = new Intent(Intent.ACTION_EDIT);
intent.setType("vnd.android.cursor.item/event");
intent.putExtra("beginTime", cal.getTimeInMillis());
intent.putExtra("allDay", true);
intent.putExtra("rrule", "FREQ=YEARLY");
intent.putExtra("endTime", cal.getTimeInMillis()+60*60*1000);
intent.putExtra("title", "A Test Event from android app");
startActivity(intent);
代码示例来源:origin: opentripplanner/OpenTripPlanner
public void setTimeZone(TimeZone timeZone) {
Calendar calendar = Calendar.getInstance(timeZone);
calendar.setTime(startTime.getTime());
startTime = calendar;
calendar = Calendar.getInstance(timeZone);
calendar.setTime(endTime.getTime());
endTime = calendar;
agencyTimeZoneOffset = timeZone.getOffset(startTime.getTimeInMillis());
}
}
代码示例来源:origin: org.codehaus.groovy/groovy
@Deprecated
public static void set(Date self, Map<Object, Integer> updates) {
Calendar cal = Calendar.getInstance();
cal.setTime(self);
set(cal, updates);
self.setTime(cal.getTimeInMillis());
}
代码示例来源:origin: spring-projects/spring-framework
calendar.setTime(date);
calendar.set(Calendar.MILLISECOND, 0);
long originalTimestamp = calendar.getTimeInMillis();
doNext(calendar, calendar.get(Calendar.YEAR));
if (calendar.getTimeInMillis() == originalTimestamp) {
calendar.add(Calendar.SECOND, 1);
doNext(calendar, calendar.get(Calendar.YEAR));
代码示例来源:origin: apache/hive
/**
* Add or subtract interval value to the specified timestamp
*/
public Timestamp timestampChange(Timestamp in, boolean add) {
Calendar c = Calendar.getInstance();
c.setTimeInMillis(in.getTime());
calendarChange(c, add);
return new Timestamp(c.getTimeInMillis());
}
代码示例来源:origin: stackoverflow.com
Calendar rightNow = Calendar.getInstance();
// offset to add since we're not UTC
long offset = rightNow.get(Calendar.ZONE_OFFSET) +
rightNow.get(Calendar.DST_OFFSET);
long sinceMidnight = (rightNow.getTimeInMillis() + offset) %
(24 * 60 * 60 * 1000);
System.out.println(sinceMidnight + " milliseconds since midnight");
代码示例来源:origin: north2016/T-MVP
public static List<String> getOldWeekDays() {
final Calendar c = Calendar.getInstance();
String[] months = new String[8];
for (int i = 0; i < 8; i++) {
months[i] = new SimpleDateFormat("MM.dd").format(new Date(c
.getTimeInMillis()));
c.add(Calendar.DAY_OF_MONTH, -1);
}
return Arrays.asList(months);
}
代码示例来源:origin: jenkinsci/jenkins
public void doRun() {
while(new Date().getTime() >= cal.getTimeInMillis()) {
LOGGER.log(Level.FINE, "cron checking {0}", cal.getTime());
try {
checkTriggers(cal);
} catch (Throwable e) {
LOGGER.log(Level.WARNING,"Cron thread throw an exception",e);
// SafeTimerTask.run would also catch this, but be sure to increment cal too.
}
cal.add(Calendar.MINUTE,1);
}
}
}
代码示例来源:origin: rey5137/material
private static long gotoFirstDayOfWeek(Calendar cal){
int dayOfWeek = cal.get(Calendar.DAY_OF_WEEK);
int firstDayOfWeek = cal.getFirstDayOfWeek();
int shift = dayOfWeek >= firstDayOfWeek ? (dayOfWeek - firstDayOfWeek) : (dayOfWeek + 7 - firstDayOfWeek);
cal.add(Calendar.DAY_OF_MONTH, -shift);
return cal.getTimeInMillis();
}
代码示例来源:origin: wangdan/AisenWeiBo
@Override
public void onTimeSet(RadialPickerLayout view, int hourOfDay, int minute) {
Logger.v(TAG, String.format("onTimeSet:hourOfDay = %d, minute = %d", hourOfDay, minute));
if (checkTiming(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH), hourOfDay, minute)) {
calendar.set(Calendar.HOUR_OF_DAY, hourOfDay);
calendar.set(Calendar.MINUTE, minute);
btnTime.setText(DateUtils.formatDate(calendar.getTimeInMillis(), getString(R.string.publish_date_format_hm)));
}
}
};
代码示例来源:origin: networknt/light-4j
private static long getNextMidNightTime() {
Calendar cal = new GregorianCalendar();
cal.set(Calendar.HOUR_OF_DAY, 0);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MILLISECOND, 0);
cal.add(Calendar.DAY_OF_MONTH, 1);
return cal.getTimeInMillis();
}
代码示例来源:origin: apache/activemq
protected static long doUpdateCurrentMonth(Calendar working, CronEntry month) throws MessageFormatException {
int currentMonth = working.get(Calendar.MONTH) + 1;
if (!isCurrent(month, currentMonth)) {
int nextMonth = getNext(month, currentMonth, working);
working.add(Calendar.MONTH, nextMonth);
// Reset to start of month.
resetToStartOfDay(working, 1);
return working.getTimeInMillis();
}
return 0L;
}
代码示例来源:origin: apache/hive
/**
* Perform month arithmetic to millis value using UTC time zone.
* @param millis
* @param months
* @return
*/
public long addMonthsToMillis(long millis, int months) {
calUtc.setTimeInMillis(millis);
calUtc.add(Calendar.MONTH, months);
return calUtc.getTimeInMillis();
}
代码示例来源:origin: square/moshi
private Date newDate(int year, int month, int day, int hour, int offset) {
Calendar calendar = new GregorianCalendar(TimeZone.getTimeZone("GMT"));
calendar.set(year, month - 1, day, hour, 0, 0);
calendar.set(Calendar.MILLISECOND, 0);
return new Date(calendar.getTimeInMillis() - TimeUnit.HOURS.toMillis(offset));
}
}
代码示例来源:origin: apache/hbase
private static Tick nextTick() {
Calendar calendar = new GregorianCalendar();
int currentHour = calendar.get(Calendar.HOUR_OF_DAY);
moveToNextHour(calendar);
return new Tick(currentHour, calendar.getTimeInMillis());
}
代码示例来源:origin: Activiti/Activiti
public static Calendar convertToTimeZone(Calendar time, TimeZone timeZone) {
Calendar foreignTime = new GregorianCalendar(timeZone);
foreignTime.setTimeInMillis(time.getTimeInMillis());
return foreignTime;
}
代码示例来源:origin: apache/rocketmq
public static long computNextHourTimeMillis() {
Calendar cal = Calendar.getInstance();
cal.setTimeInMillis(System.currentTimeMillis());
cal.add(Calendar.DAY_OF_MONTH, 0);
cal.add(Calendar.HOUR_OF_DAY, 1);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MILLISECOND, 0);
return cal.getTimeInMillis();
}
代码示例来源:origin: geoserver/geoserver
public Range getSearchRangeOnSingleValue(Object value) {
if (Date.class.isAssignableFrom(dataType)) {
Date center = (Date) value;
Calendar cal = Calendar.getInstance();
cal.setTime(center);
cal.setTimeInMillis(cal.getTimeInMillis() - before.longValue());
Date min = cal.getTime();
cal.setTime(center);
cal.setTimeInMillis(cal.getTimeInMillis() + after.longValue());
Date max = cal.getTime();
return new DateRange(min, max);
}
// TODO: add support for Number, e.g., elevation
throw new IllegalArgumentException("Unsupported value type " + dataType);
}
内容来源于网络,如有侵权,请联系作者删除!