当前位置: 首页>>代码示例>>Java>>正文


Java Calendar.getTimeInMillis方法代码示例

本文整理汇总了Java中java.util.Calendar.getTimeInMillis方法的典型用法代码示例。如果您正苦于以下问题:Java Calendar.getTimeInMillis方法的具体用法?Java Calendar.getTimeInMillis怎么用?Java Calendar.getTimeInMillis使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.util.Calendar的用法示例。


在下文中一共展示了Calendar.getTimeInMillis方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getDaysBetween

import java.util.Calendar; //导入方法依赖的package包/类
/**
	 * Calculates the number of days between two calendar days in a manner
	 * which is independent of the Calendar type used.
	 *
	 * @param d1    The first date.
	 * @param d2    The second date.
	 *
	 * @return      The number of days between the two dates.  Zero is
	 *              returned if the dates are the same, one if the dates are
	 *              adjacent, etc.  The order of the dates
	 *              does not matter, the value returned is always >= 0.
	 *              If Calendar types of d1 and d2
	 *              are different, the result may not be accurate.
	 */
	public static int getDaysBetween( Calendar d1, Calendar d2 ) {
		if ( d1.after(d2) ) {
			// swap dates so that d1 is start and d2 is end
			Calendar swap = d1;
			d1 = d2;
			d2 = swap;
		}
		long days = (d2.getTimeInMillis() - d1.getTimeInMillis()) / (1000 * 60 * 60 * 24);
		return (int) days;
		
		
//		int days = d2.get(Calendar.DAY_OF_YEAR) - d1.get(Calendar.DAY_OF_YEAR);
//		int y2   = d2.get(Calendar.YEAR);
//		if (d1.get(Calendar.YEAR) != y2) {
//			d1 = (Calendar) d1.clone();
//			do {
//				days += d1.getActualMaximum(Calendar.DAY_OF_YEAR);
//				d1.add(Calendar.YEAR, 1);
//			} while (d1.get(Calendar.YEAR) != y2);
//		}
//		return days;
	}
 
开发者ID:skarna1,项目名称:javaportfolio,代码行数:37,代码来源:XIRRData.java

示例2: getDayBetween

import java.util.Calendar; //导入方法依赖的package包/类
/**
 * 间隔天数
 * 
 * @param startDate
 * @param endDate
 * @return
 */
public static final Integer getDayBetween(Date startDate, Date endDate) {
	Calendar start = Calendar.getInstance();
	start.setTime(startDate);
	start.set(Calendar.HOUR_OF_DAY, 0);
	start.set(Calendar.MINUTE, 0);
	start.set(Calendar.SECOND, 0);
	start.set(Calendar.MILLISECOND, 0);
	Calendar end = Calendar.getInstance();
	end.setTime(endDate);
	end.set(Calendar.HOUR_OF_DAY, 0);
	end.set(Calendar.MINUTE, 0);
	end.set(Calendar.SECOND, 0);
	end.set(Calendar.MILLISECOND, 0);

	long n = end.getTimeInMillis() - start.getTimeInMillis();
	return (int) (n / (60 * 60 * 24 * 1000l));
}
 
开发者ID:guokezheng,项目名称:automat,代码行数:25,代码来源:DateUtil.java

示例3: getMinusDaysBetweenTwoDate

import java.util.Calendar; //导入方法依赖的package包/类
public static int getMinusDaysBetweenTwoDate(long endTime, long startTime) {
    Date endDate = new Date(endTime);
    Date beginDate = new Date(startTime);
    Calendar c = Calendar.getInstance();
    c.setTime(endDate);
    c.set(11, 0);
    c.set(12, 0);
    c.set(13, 0);
    c.set(14, 0);
    long endMilliSec = c.getTimeInMillis();
    c.setTime(beginDate);
    c.set(11, 0);
    c.set(12, 0);
    c.set(13, 0);
    c.set(14, 0);
    return (int) ((endMilliSec - c.getTimeInMillis()) / 86400000);
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:18,代码来源:LetvUtils.java

示例4: fastDateCreate

import java.util.Calendar; //导入方法依赖的package包/类
final static Date fastDateCreate(boolean useGmtConversion, Calendar gmtCalIfNeeded, Calendar cal, int year, int month, int day) {

        Calendar dateCal = cal;

        if (useGmtConversion) {

            if (gmtCalIfNeeded == null) {
                gmtCalIfNeeded = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
            }

            dateCal = gmtCalIfNeeded;
        }

        synchronized (dateCal) {
            java.util.Date origCalDate = dateCal.getTime();
            try {
                dateCal.clear();
                dateCal.set(Calendar.MILLISECOND, 0);

                // why-oh-why is this different than java.util.date, in the year part, but it still keeps the silly '0' for the start month????
                dateCal.set(year, month - 1, day, 0, 0, 0);

                long dateAsMillis = dateCal.getTimeInMillis();

                return new Date(dateAsMillis);
            } finally {
                dateCal.setTime(origCalDate);
            }
        }

    }
 
开发者ID:bragex,项目名称:the-vigilantes,代码行数:32,代码来源:TimeUtil.java

示例5: setTimeToZeroInCurrentTimeZone

import java.util.Calendar; //导入方法依赖的package包/类
/**
 * Sets hour, minute, second and millisecond of the provided time stamp to
 * zero and converts it to the server time zone.
 * 
 * @param timeStamp
 *            the time stamp to convert
 * @return the time stamp representing the day 00:00:00 000 passed in the
 *         time stamp in the current time zone
 */
private static final long setTimeToZeroInCurrentTimeZone(long timeStamp) {
    Calendar cal = Calendar.getInstance();
    cal.setTimeInMillis(timeStamp);
    cal.set(Calendar.HOUR_OF_DAY, 0);
    cal.set(Calendar.MINUTE, 0);
    cal.set(Calendar.SECOND, 0);
    cal.set(Calendar.MILLISECOND, 0);
    return cal.getTimeInMillis();
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:19,代码来源:GetRevenueListCommand.java

示例6: test50

import java.util.Calendar; //导入方法依赖的package包/类
@Test
public void test50() {
    Calendar cal = Calendar.getInstance();
    Timestamp ts1 = new Timestamp(System.currentTimeMillis());
    cal.setTimeInMillis(ts1.getTime());
    cal.add(Calendar.MONTH, -1);
    cal.set(Calendar.DAY_OF_MONTH, cal.getActualMaximum(Calendar.DAY_OF_MONTH));
    Timestamp ts2 = new Timestamp(cal.getTimeInMillis());
    assertTrue(!ts1.equals(ts2) && ts1.equals(ts1));
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:11,代码来源:TimestampTests.java

示例7: getMidnightTime

import java.util.Calendar; //导入方法依赖的package包/类
private long getMidnightTime() {
    Calendar c = Calendar.getInstance();
    c.set(Calendar.MILLISECOND, 0);
    c.set(Calendar.SECOND, 0);
    c.set(Calendar.MINUTE, 0);
    c.set(Calendar.HOUR, 0);
    return c.getTimeInMillis();
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:9,代码来源:ResultsOutlineCellRenderer.java

示例8: getFirstDayOfMonth

import java.util.Calendar; //导入方法依赖的package包/类
/**
 * 返回月的第一天
 * 
 * @return
 */
public static long getFirstDayOfMonth()
{
	Calendar calendar = new GregorianCalendar();

	calendar.set(Calendar.DAY_OF_MONTH, 1);

	calendar.set(Calendar.HOUR_OF_DAY, 0);
	calendar.set(Calendar.MINUTE, 0);
	calendar.set(Calendar.SECOND, 0);
	calendar.set(Calendar.MILLISECOND, 0);

	Log.D(TAG, "getFirstDayOfMonth: " + calendar.getTime());
	return calendar.getTimeInMillis();
}
 
开发者ID:benniaobuguai,项目名称:android-project-gallery,代码行数:20,代码来源:DateUtils.java

示例9: testToSqlTime

import java.util.Calendar; //导入方法依赖的package包/类
@Test
public void testToSqlTime()
{
	com.google.cloud.Timestamp ts = com.google.cloud.Timestamp.parseTimestamp("2000-01-01T13:15:10.0010001Z");
	Time t1 = CloudSpannerConversionUtil.toSqlTime(ts);
	Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
	cal.set(2000, 0, 1, 13, 15, 10);
	cal.set(Calendar.MILLISECOND, 1);
	Time t2 = new Time(cal.getTimeInMillis());
	assertEquals(t2.getTime(), t1.getTime());
	assertEquals(t2, t1);
}
 
开发者ID:olavloite,项目名称:spanner-jdbc,代码行数:13,代码来源:CloudSpannerConversionUtilTest.java

示例10: updateNextTriggerTime

import java.util.Calendar; //导入方法依赖的package包/类
public void updateNextTriggerTime()
{
	int newEnd = this.end < this.start ? this.end + 1440 : this.end;
	long currentTime = MainDialog.now;
	Calendar calendar2 = Calendar.getInstance();
	calendar2.setTimeInMillis(currentTime);
	calendar2.set(Calendar.HOUR_OF_DAY, this.start / 60);
	calendar2.set(Calendar.MINUTE, this.start % 60);
	calendar2.set(Calendar.SECOND, 0);
	calendar2.set(Calendar.MILLISECOND, 0);
	long m = calendar2.getTimeInMillis();
	long n = m + ((newEnd - this.start) * 60000L);
	if (n < currentTime)
	{
		calendar2 = Calendar.getInstance();
		calendar2.setTimeInMillis(currentTime + 86400000L);
		calendar2.set(Calendar.HOUR_OF_DAY, this.start / 60);
		calendar2.set(Calendar.MINUTE, this.start % 60);
		calendar2.set(Calendar.SECOND, 0);
		calendar2.set(Calendar.MILLISECOND, 0);
		m = calendar2.getTimeInMillis();
		n = m + ((newEnd - this.start) * 60000L);
	}
	else if ((n - currentTime) >= 86400000L)
	{
		calendar2 = Calendar.getInstance();
		calendar2.setTimeInMillis(currentTime - 86400000L);
		calendar2.set(Calendar.HOUR_OF_DAY, this.start / 60);
		calendar2.set(Calendar.MINUTE, this.start % 60);
		calendar2.set(Calendar.SECOND, 0);
		calendar2.set(Calendar.MILLISECOND, 0);
		m = calendar2.getTimeInMillis();
		n = m + ((newEnd - this.start) * 60000L);
	}
	this.nextStartTime = m;
	this.nextEndTime = n;
}
 
开发者ID:PolyphasicDevTeam,项目名称:NoMoreOversleeps,代码行数:38,代码来源:SleepEntry.java

示例11: testRoundDownTimeStampHoursWithTimeZone

import java.util.Calendar; //导入方法依赖的package包/类
/**
 * Tests if the timestamp with the custom timezone is properly rounded down
 * to 2 hours.
 */
@Test
public void testRoundDownTimeStampHoursWithTimeZone() {
  Calendar cal = BASE_CALENDAR_WITH_CUSTOM_TIMEZONE;
  Calendar cal2 = createCalendar(2012, 5, 15, 14, 0, 0, 0, CUSTOM_TIMEZONE);

  long timeToVerify = cal2.getTimeInMillis();
  long withoutTimeZone = TimestampRoundDownUtil.roundDownTimeStampHours(
      cal.getTimeInMillis(), 2);
  long withTimeZone = TimestampRoundDownUtil.roundDownTimeStampHours(
      cal.getTimeInMillis(), 2, CUSTOM_TIMEZONE);

  assertThat(withoutTimeZone, not(equalTo(timeToVerify)));
  Assert.assertEquals(withTimeZone, timeToVerify);
}
 
开发者ID:moueimei,项目名称:flume-release-1.7.0,代码行数:19,代码来源:TestTimestampRoundDownUtil.java

示例12: getTimesMorning

import java.util.Calendar; //导入方法依赖的package包/类
public static long getTimesMorning(Long timestamp) {
    Calendar cal = Calendar.getInstance();
    cal.setTimeInMillis(timestamp * 1000);
    cal.set(Calendar.HOUR_OF_DAY, 0);
    cal.set(Calendar.SECOND, 0);
    cal.set(Calendar.MINUTE, 0);
    cal.set(Calendar.MILLISECOND, 0);
    return (int) (cal.getTimeInMillis() / 1000);
}
 
开发者ID:weiboad,项目名称:fiery,代码行数:10,代码来源:DateTimeHelper.java

示例13: toTime

import java.util.Calendar; //导入方法依赖的package包/类
private long toTime(final TemporalAccessor temporalAccessor) {
	Calendar calendar = Calendar.getInstance();
	setField(calendar, Calendar.YEAR, temporalAccessor, ChronoField.YEAR, 0, 1970);
	setField(calendar, Calendar.MONTH, temporalAccessor, ChronoField.MONTH_OF_YEAR, -1, 0);
	setField(calendar, Calendar.DATE, temporalAccessor, ChronoField.DAY_OF_MONTH, 0, 1);
	setField(calendar, Calendar.HOUR_OF_DAY, temporalAccessor, ChronoField.HOUR_OF_DAY, 0, 0);
	setField(calendar, Calendar.MINUTE, temporalAccessor, ChronoField.MINUTE_OF_HOUR, 0, 0);
	setField(calendar, Calendar.SECOND, temporalAccessor, ChronoField.SECOND_OF_MINUTE, 0, 0);
	setField(calendar, Calendar.MILLISECOND, temporalAccessor, ChronoField.MILLI_OF_SECOND, 0, 0);
	return calendar.getTimeInMillis();
}
 
开发者ID:future-architect,项目名称:uroborosql,代码行数:12,代码来源:DateTimeApiPropertyMapperTest.java

示例14: parseExpires

import java.util.Calendar; //导入方法依赖的package包/类
/** Parse a date as specified in RFC 6265, section 5.1.1. */
private static long parseExpires(String s, int pos, int limit) {
  pos = dateCharacterOffset(s, pos, limit, false);

  int hour = -1;
  int minute = -1;
  int second = -1;
  int dayOfMonth = -1;
  int month = -1;
  int year = -1;
  Matcher matcher = TIME_PATTERN.matcher(s);

  while (pos < limit) {
    int end = dateCharacterOffset(s, pos + 1, limit, true);
    matcher.region(pos, end);

    if (hour == -1 && matcher.usePattern(TIME_PATTERN).matches()) {
      hour = Integer.parseInt(matcher.group(1));
      minute = Integer.parseInt(matcher.group(2));
      second = Integer.parseInt(matcher.group(3));
    } else if (dayOfMonth == -1 && matcher.usePattern(DAY_OF_MONTH_PATTERN).matches()) {
      dayOfMonth = Integer.parseInt(matcher.group(1));
    } else if (month == -1 && matcher.usePattern(MONTH_PATTERN).matches()) {
      String monthString = matcher.group(1).toLowerCase(Locale.US);
      month = MONTH_PATTERN.pattern().indexOf(monthString) / 4; // Sneaky! jan=1, dec=12.
    } else if (year == -1 && matcher.usePattern(YEAR_PATTERN).matches()) {
      year = Integer.parseInt(matcher.group(1));
    }

    pos = dateCharacterOffset(s, end + 1, limit, false);
  }

  // Convert two-digit years into four-digit years. 99 becomes 1999, 15 becomes 2015.
  if (year >= 70 && year <= 99) year += 1900;
  if (year >= 0 && year <= 69) year += 2000;

  // If any partial is omitted or out of range, return -1. The date is impossible. Note that leap
  // seconds are not supported by this syntax.
  if (year < 1601) throw new IllegalArgumentException();
  if (month == -1) throw new IllegalArgumentException();
  if (dayOfMonth < 1 || dayOfMonth > 31) throw new IllegalArgumentException();
  if (hour < 0 || hour > 23) throw new IllegalArgumentException();
  if (minute < 0 || minute > 59) throw new IllegalArgumentException();
  if (second < 0 || second > 59) throw new IllegalArgumentException();

  Calendar calendar = new GregorianCalendar(UTC);
  calendar.setLenient(false);
  calendar.set(Calendar.YEAR, year);
  calendar.set(Calendar.MONTH, month - 1);
  calendar.set(Calendar.DAY_OF_MONTH, dayOfMonth);
  calendar.set(Calendar.HOUR_OF_DAY, hour);
  calendar.set(Calendar.MINUTE, minute);
  calendar.set(Calendar.SECOND, second);
  calendar.set(Calendar.MILLISECOND, 0);
  return calendar.getTimeInMillis();
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:57,代码来源:Cookie.java

示例15: formatLongTypeTimeToString

import java.util.Calendar; //导入方法依赖的package包/类
public static String formatLongTypeTimeToString(Context context, long time) {
    long OFFSET_DAY = 3600 * 24;
    String timeYes = context.getString(R.string.udesk_im_time_format_yday);
    String timeQt = context.getString(R.string.udesk_im_time_format_dby);
    String timeDate = "yyyy/MM/dd";
    Calendar calendar = Calendar.getInstance();
    StringBuilder build = new StringBuilder();
    SimpleDateFormat sdf = new SimpleDateFormat("HH:mm");

    // 解析需要转化时间
    calendar.setTimeInMillis(time);
    int year = calendar.get(Calendar.YEAR);
    int day = calendar.get(Calendar.DAY_OF_YEAR);

    // 拼接 转化结果
    build.append(" ").append(sdf.format(calendar.getTime()));// 先添加

    // 先解析当前时间。取出当前年,日 等信息
    calendar.setTimeInMillis(System.currentTimeMillis());
    int nowYear = calendar.get(Calendar.YEAR);
    int nowDay = calendar.get(Calendar.DAY_OF_YEAR);

    if (year != nowYear) {// 不是一年内
        calendar.set(Calendar.HOUR_OF_DAY, 0); // 凌晨1点
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.SECOND, 0);

        if ((calendar.getTimeInMillis() - time) <= OFFSET_DAY) {// 昨天
            return timeYes;
        } else if ((calendar.getTimeInMillis() - time) <= (OFFSET_DAY << 2)) {// 前天
            // 。这里不用判断是否大于OFFSET_DAY
            return timeQt;
        } else {
            sdf.applyLocalizedPattern(timeDate);
            return sdf.format(time);
        }

    } else if (day == nowDay) {// 这里是一年内的当天
        // 当天的话 就不用管了
    } else {// 一年内
        int dayOffset = (nowDay - day);// nowDay要大一些
        if (dayOffset == 0) {
            // 同一天不用 添加日期判断
        } else if (dayOffset == 1) {// 1表示差一天,即昨天
            return timeYes;
        } else if (dayOffset == 2) {// 1表示差两天,即前天
            return timeQt;
        } else {
            timeDate = "MM月dd日";
            sdf.applyLocalizedPattern(timeDate);
            return sdf.format(time);
        }
    }

    return build.toString();
}
 
开发者ID:lennyup,项目名称:react-native-udesk,代码行数:57,代码来源:UdeskUtil.java


注:本文中的java.util.Calendar.getTimeInMillis方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。