SimpleDateFormat parse方法获取到的时间戳为00点 判断上下午

SimpleDateFormat simpleDateFormat =new SimpleDateFormat("yyyy-MM-dd hh:mm:ss")
Date time= simpleDateFormat.parse("2022-10-12 13:22");
 
//yyyy-MM-dd hh:mm:ss 格式化后获取到的时间戳是12小时制
//yyyy-MM-dd HH:mm:ss 格式化后获取到的时间戳是24小时制

判断上下午

long time = System.currentTimeMillis();
final Calendar mCalendar = Calendar.getInstance();
mCalendar.setTimeInMillis(time);
int hour = mCalendar.get(Calendar.HOUR);
int apm = mCalendar.get(Calendar.AM_PM);

apm=0 表示上午,apm=1表示下午。

其他的都能根据上面的hour一样的方式找到年月日时分秒

代码对应的时间

年-月-日 时:分:秒 星期(周)

 yyyy-MM-dd  hh:mm:ss E (EEEE)

猜你喜欢

转载自blog.csdn.net/afufufufu/article/details/127280809
今日推荐