android-Calendar

private void dateBasicFunction() {
    Calendar rightNow = Calendar.getInstance();
    Log.d("Date", rightNow.getTime().toString()); //time Tue Sep 17 03:28:35 EDT 2019
    Log.d("Date", String.valueOf(rightNow.getTimeInMillis())); //getTimeInMillis 1568705620687
    Log.d("Date", String.valueOf(rightNow.getTimeZone())); //libcore.util.ZoneInfo[id="America/New_York",mRawOffset=-18000000,mEarliestRawOffset=-18000000,mUseDst=true,mDstSavings=3600000,transitions=235]
    Log.d("Date", String.valueOf(rightNow.getTimeZone().getDisplayName())); //getTimeZone.getDisplayName Eastern Standard Time
    Log.d("Date", String.valueOf(rightNow.getFirstDayOfWeek())); //getFirstDayOfWeek 1
    Locale[] locales = Calendar.getAvailableLocales();
    int amvalue = rightNow.get(Calendar.AM);//1
    if (rightNow.get(Calendar.AM_PM) == Calendar.AM) {
     //判断是上午还是下午
        Log.d("Date", "现在是上午");
    } else {
        Log.d("Date", "现在是下午");
    }

    int year = rightNow.get(Calendar.YEAR);//2019 年份
    int month = rightNow.get(Calendar.MONTH);//8 JANUARY 一月份返回的默认值是0,那么后面的一次类推,因此想得到正确的月份表达方式,就应当在后面+1 -> rightNow.get(Calendar.MONTH) + 1
    int day = rightNow.get(Calendar.DAY_OF_MONTH);//17 几号
    int hour = rightNow.get(Calendar.HOUR);//4 小时,目前可以看到是12小时制的表示
    int minute = rightNow.get(Calendar.MINUTE);//9 分钟
    int second = rightNow.get(Calendar.SECOND);//53 秒
    int am_pm = rightNow.get(Calendar.AM_PM);//0
    int hour_of_day = rightNow.get(Calendar.HOUR_OF_DAY);//4 几点
    int day_of_week = rightNow.get(Calendar.DAY_OF_WEEK);//3 可以同Calender.SUNDAY, MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, and SATURDAY来比较判断是周几,周日默认为1,这里的三就是周二了
    int day_of_week_in_month = rightNow.get(Calendar.DAY_OF_WEEK_IN_MONTH);//3 确定今天在本月的第几周
}

你可能感兴趣的:(时间)