當前位置: 首頁>>代碼示例>>Java>>正文


Java Calendar.setTimeInMillis方法代碼示例

本文整理匯總了Java中java.util.Calendar.setTimeInMillis方法的典型用法代碼示例。如果您正苦於以下問題:Java Calendar.setTimeInMillis方法的具體用法?Java Calendar.setTimeInMillis怎麽用?Java Calendar.setTimeInMillis使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.util.Calendar的用法示例。


在下文中一共展示了Calendar.setTimeInMillis方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: setBirthdayReminder

import java.util.Calendar; //導入方法依賴的package包/類
/**
 * Set when to remind about birthdays
 * @param context - the current app context
 * @param plant - the plant whose birthday is reminded of
 * @param id - the id of the plant
 */
public void setBirthdayReminder(Context context, Plant plant, int id) {
    Intent intent = new Intent(context, BirthdayReceiver.class);
    intent.putExtra("name", plant.getName());
    intent.putExtra("species", plant.getSpecies());
    intent.putExtra("birthday", plant.getBirthday());
    intent.putExtra("id", id);
    PendingIntent pendingIntent = PendingIntent.getBroadcast(context, id, intent, 0);
    Calendar now = Calendar.getInstance();
    now.setTimeInMillis(System.currentTimeMillis());
    Calendar birthday = Calendar.getInstance();
    birthday.setTimeInMillis(plant.getBirthday());
    birthday.set(Calendar.YEAR, now.get((Calendar.YEAR)));
    if (birthday.getTimeInMillis() < now.getTimeInMillis()) {
        birthday.set(Calendar.YEAR, now.get((Calendar.YEAR)) + 1);
    }
    AlarmManager am = (AlarmManager)context.getSystemService(ALARM_SERVICE);
    if (am != null) {
        am.set(AlarmManager.RTC_WAKEUP, birthday.getTimeInMillis(), pendingIntent);
    }
}
 
開發者ID:iskandergaba,項目名稱:Botanist,代碼行數:27,代碼來源:DatabaseManager.java

示例2: formatDateChat

import java.util.Calendar; //導入方法依賴的package包/類
public static String formatDateChat(long date) {
    try {
        Calendar rightNow = Calendar.getInstance();
        int year = rightNow.get(Calendar.YEAR);

        rightNow.setTimeInMillis(date * 1000);
        int dateYear = rightNow.get(Calendar.YEAR);

        if (year == dateYear) {
            return getInstance().chatDate.format(date * 1000);
        }
        return getInstance().chatFullDate.format(date * 1000);
    } catch (Exception e) {
        FileLog.e("tmessages", e);
    }
    return "LOC_ERR: formatDateChat";
}
 
開發者ID:pooyafaroka,項目名稱:PlusGram,代碼行數:18,代碼來源:LocaleController.java

示例3: getRepeatingNotificationTime

import java.util.Calendar; //導入方法依賴的package包/類
/**
 * Returns time in milliseconds for +1 day if the hour & minute has already passed that day
 * @param hourOfDay
 * @param minute
 * @return
 */
private long getRepeatingNotificationTime(int hourOfDay, int minute) {
    Calendar calendar = Calendar.getInstance();
    calendar.setTimeInMillis(System.currentTimeMillis());

    if (calendar.get(Calendar.HOUR_OF_DAY) > hourOfDay) {
        calendar.add(Calendar.DAY_OF_YEAR, 1);
        calendar.set(Calendar.HOUR_OF_DAY, hourOfDay);
    }
    else if (calendar.get(Calendar.HOUR_OF_DAY) == hourOfDay) {
        if (calendar.get(Calendar.MINUTE) >= minute) {
            calendar.add(Calendar.DAY_OF_YEAR, 1);
            calendar.set(Calendar.MINUTE, minute);
        }
    } else {
        calendar.set(Calendar.HOUR_OF_DAY, hourOfDay);
        calendar.set(Calendar.MINUTE, minute);
    }

    return calendar.getTimeInMillis();
}
 
開發者ID:Dentacoin,項目名稱:aftercare-app-android,代碼行數:27,代碼來源:DCLocalNotificationsManager.java

示例4: onEnabled

import java.util.Calendar; //導入方法依賴的package包/類
@Override
public void onEnabled(Context context) {
    super.onEnabled(context);
    AlarmManager alarmMgr = (AlarmManager) context.getSystemService(
            Context.ALARM_SERVICE);
    long intervalClock = 60000;
    long intervalWeather = 7200000;

    Calendar calendar = Calendar.getInstance();
    calendar.setTimeInMillis(System.currentTimeMillis());

    alarmMgr.setRepeating(AlarmManager.RTC, calendar.getTimeInMillis(),
            intervalClock, createClockTickIntent(context));

    alarmMgr.setRepeating(AlarmManager.RTC, calendar.getTimeInMillis(),
            intervalWeather, createWeatherUpdateIntent(context));
}
 
開發者ID:SEALiu,項目名稱:Calendouer,代碼行數:18,代碼來源:ClockWidgetProvider.java

示例5: toDateString

import java.util.Calendar; //導入方法依賴的package包/類
private String toDateString(long timeMilli) {
    Calendar calc = Calendar.getInstance();
    calc.setTimeInMillis(timeMilli);
    return String.format(Locale.CHINESE, "%04d.%02d.%02d %02d:%02d:%02d:%03d",
            calc.get(Calendar.YEAR), calc.get(Calendar.MONTH) + 1, calc.get(Calendar.DAY_OF_MONTH),
            calc.get(Calendar.HOUR_OF_DAY), calc.get(Calendar.MINUTE), calc.get(Calendar.SECOND), calc.get(Calendar.MILLISECOND));
}
 
開發者ID:huashengzzz,項目名稱:SmartChart,代碼行數:8,代碼來源:CrashHandler.java

示例6: formatYYYYMMDDHHMMSS_ms

import java.util.Calendar; //導入方法依賴的package包/類
public static String formatYYYYMMDDHHMMSS_ms(long l)
{
	Calendar cal = new GregorianCalendar();
	cal.setTimeInMillis(l);
	
	Date date = cal.getTime();
	SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMddHHmmss");
	String cs = formatter.format(date) ;
	return cs ;
}
 
開發者ID:costea7,項目名稱:ChronoBike,代碼行數:11,代碼來源:Time_ms.java

示例7: onStartCommand

import java.util.Calendar; //導入方法依賴的package包/類
@Override
public int onStartCommand(final Intent intent, int flags, int startId) {

    settingsprefs = getSharedPreferences("settings", 0);

    now = System.currentTimeMillis();

    if (intent != null) {
        if (intent.getExtras() != null) {
            mode = (String) intent.getExtras().get("mode");
            additionalShakeDelay = intent.getBooleanExtra("additionalShakeDelay", false);
        }
    }

    // We want this service to continue running until it is explicitly
    // stopped, so return sticky.
    nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);

    long endTime = 0;
    switch (mode) {
        case "boot":
            endTime = settingsprefs.getLong("bootShutdownTime", 0);
            break;
        case "minute":
            endTime = settingsprefs.getLong("minuteShutdownTime", 0);
            break;
        case "time":
            endTime = settingsprefs.getLong("timeShutdownTime", 0);
            break;
    }
    lastendTime = endTime;
    duration = endTime - now;
    Calendar calll = Calendar.getInstance();
    calll.setTimeInMillis(endTime);
    createCountDownTimer();
    return START_STICKY;
}
 
開發者ID:jonathansautter,項目名稱:AutoOff,代碼行數:38,代碼來源:NotificationService.java

示例8: isTheSameYear

import java.util.Calendar; //導入方法依賴的package包/類
private static boolean isTheSameYear(long value) {
    Calendar current = Calendar.getInstance();
    Calendar old = Calendar.getInstance();
    old.clear();
    old.setTimeInMillis(value);
    int cyear = current.get(Calendar.YEAR);
    int oyear = old.get(Calendar.YEAR);
    return cyear == oyear;
}
 
開發者ID:Onelio,項目名稱:ConnectU,代碼行數:10,代碼來源:UpdaterHelper.java

示例9: formatTimeStamp

import java.util.Calendar; //導入方法依賴的package包/類
/**
 * Format the long System.currentTimeMillis() to a better looking timestamp. Uses a calendar
 *   object to format with the user's current time zone.
 * @param timeStamp
 * @return
 */
public static String formatTimeStamp(long timeStamp){
    // Create a DateFormatter object for displaying date in specified format.
    SimpleDateFormat formatter = new SimpleDateFormat("h:mm.ss a");

    // Create a calendar object that will convert the date and time value in milliseconds to date.
    Calendar calendar = Calendar.getInstance();
    calendar.setTimeInMillis(timeStamp);
    return formatter.format(calendar.getTime());
}
 
開發者ID:newbie007fx,項目名稱:newwebrtc,代碼行數:16,代碼來源:ChatAdapter.java

示例10: formatCreationTime

import java.util.Calendar; //導入方法依賴的package包/類
/**
 * Converts millis to a formatted Date String.
 *
 * @param millis Duration in millis to convert to a string
 *
 * @return Formatted string: yyyy-MM-dd HH:mm:ss.
 */
private static String formatCreationTime(long millis) {
    final DateFormat dateFormatter =
            new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    Calendar calendar = Calendar.getInstance();
    calendar.setTimeInMillis(millis);
    return (dateFormatter.format(calendar.getTime()));
}
 
開發者ID:shlee89,項目名稱:athena,代碼行數:15,代碼來源:TopologyCommand.java

示例11: ArrNumMinute

import java.util.Calendar; //導入方法依賴的package包/類
/**
 * Is the method invoked to calculate the number of minutes in the log (Variable)
 */
private void ArrNumMinute() {
	ArrMinute = new Vector<double[]>();
	double i[];
	Calendar cal = Calendar.getInstance();
	cal.setTime(new Date((long) v.getValue(0)));
	Calendar cal2 = Calendar.getInstance();
	int y = 0;
	boolean k = false;
	int z = 0;
	cal2.setTimeInMillis((long) v.getValue(z));
	while (z < v.Size()) {
		if (cal.get(Calendar.YEAR) == cal2.get(Calendar.YEAR) && cal.get(Calendar.MONTH) == cal2.get(Calendar.MONTH)
				&& cal.get(Calendar.DATE) == cal2.get(Calendar.DATE) && cal.get(Calendar.HOUR_OF_DAY) == cal2.get(Calendar.HOUR_OF_DAY)
				&& cal.get(Calendar.MINUTE) == cal2.get(Calendar.MINUTE)) {
			y++;
		} else {
			k = false;
			i = new double[2];
			i[0] = cal.getTimeInMillis();
			i[1] = y;
			ArrMinute.addElement(i);
			if (cal.get(Calendar.MINUTE) == 59 && cal.get(Calendar.HOUR_OF_DAY) != 23) {
				cal.roll(Calendar.HOUR_OF_DAY, true);
			}
			if (cal.get(Calendar.MINUTE) == 59 && cal.get(Calendar.HOUR_OF_DAY) == 23) {
				cal.roll(Calendar.HOUR_OF_DAY, true);
				cal.roll(Calendar.DAY_OF_YEAR, true);
			}
			cal.roll(Calendar.MINUTE, true);
			if (cal.get(Calendar.YEAR) == cal2.get(Calendar.YEAR) && cal.get(Calendar.MONTH) == cal2.get(Calendar.MONTH)
					&& cal.get(Calendar.DAY_OF_YEAR) == cal2.get(Calendar.DAY_OF_YEAR)
					&& cal.get(Calendar.HOUR_OF_DAY) == cal2.get(Calendar.HOUR_OF_DAY) && cal.get(Calendar.MINUTE) == cal2.get(Calendar.MINUTE)) {
				y = 1;
			} else {
				y = 0;
				k = true;
			}
		}
		if (k != true) {
			z++;
			if (z < v.Size()) {
				cal2.setTimeInMillis((long) v.getValue(z));
			}
		}
	}
	i = new double[2];
	i[0] = cal.getTimeInMillis();
	i[1] = y;
	ArrMinute.addElement(i);
}
 
開發者ID:max6cn,項目名稱:jmt,代碼行數:54,代碼來源:GraphArrivalPanel.java

示例12: timeMillisToHumanString

import java.util.Calendar; //導入方法依賴的package包/類
public static String timeMillisToHumanString(final long t) {
    Calendar cal = Calendar.getInstance();
    cal.setTimeInMillis(t);
    return String.format("%04d%02d%02d%02d%02d%02d%03d", cal.get(Calendar.YEAR), cal.get(Calendar.MONTH) + 1,
        cal.get(Calendar.DAY_OF_MONTH), cal.get(Calendar.HOUR_OF_DAY), cal.get(Calendar.MINUTE), cal.get(Calendar.SECOND),
        cal.get(Calendar.MILLISECOND));
}
 
開發者ID:y123456yz,項目名稱:reading-and-annotate-rocketmq-3.4.6,代碼行數:8,代碼來源:UtilAll.java

示例13: testRoundTrip

import java.util.Calendar; //導入方法依賴的package包/類
/**
 * Tests a complete round trip.
 */
@Test
public void testRoundTrip() throws ParseException
{
    Calendar calendar = new GregorianCalendar( GMT, Locale.ROOT );
    calendar.setTimeInMillis( 123456789000L ); // default format is without millis

    // create form calendar
    GeneralizedTime generalizedTime1 = new GeneralizedTime( calendar );

    // get the string value
    String gt1 = generalizedTime1.toGeneralizedTime();
    Calendar calendar1 = generalizedTime1.getCalendar();

    // create from string value
    GeneralizedTime generalizedTime2 = new GeneralizedTime( gt1 );

    // get the calendar value 
    Calendar calendar2 = generalizedTime2.getCalendar();
    String gt2 = generalizedTime2.toGeneralizedTime();

    // assert that all are equal
    assertEquals( calendar, calendar1 );
    assertEquals( calendar, calendar2 );
    assertEquals( calendar1, calendar2 );
    assertEquals( gt1, gt2 );
    assertTrue( calendar.isLenient() );
    assertTrue( calendar1.isLenient() );
    assertTrue( calendar2.isLenient() );
}
 
開發者ID:apache,項目名稱:directory-ldap-api,代碼行數:33,代碼來源:GeneralizedTimeTest.java

示例14: 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

示例15: getFirstOfMonth

import java.util.Calendar; //導入方法依賴的package包/類
/**
 * 獲取當月第一天的時間(毫秒值)
 *
 * @param mills
 * @return
 */
public static long getFirstOfMonth(long mills) {
    Calendar calendar = Calendar.getInstance();
    calendar.setTimeInMillis(mills);
    calendar.set(Calendar.DAY_OF_MONTH, 1);

    return calendar.getTimeInMillis();
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:14,代碼來源:Kits.java


注:本文中的java.util.Calendar.setTimeInMillis方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。