一、前言
对于Joda-Time中Date-Time的dayOfWeek,dayOfMonth日期计算的方法,一开始感觉没有那么好理解,那么通过代码实践来更好的理解一下这些日期计算方法。
二、正文
1992-11-10 09:08:07 日期计算
DateTimeFormatter formatter = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss");
DateTime dateTime = formatter.parseDateTime("1992-11-10 09:08:07");
//星期二
String dayOfWeek = dateTime.dayOfWeek().getAsShortText();
//10
String dayOfMonth = dateTime.dayOfMonth().getAsShortText();
//315
String dayOfYear = dateTime.dayOfYear().getAsShortText();
//9
String hourOfDay = dateTime.hourOfDay().getAsShortText();
//十一月
String monthOfYear = dateTime.monthOfYear().getAsShortText();
//8
String minuteOfHour = dateTime.minuteOfHour().getAsShortText();
//7
String secondOfMinute = dateTime.secondOfMinute().getAsShortText();
//32887
String secondOfDay = dateTime.secondOfDay().getAsShortText();
//46
String weekOfWeekyear = dateTime.weekOfWeekyear().getAsShortText();
//1992
String weekyear = dateTime.weekyear().getAsShortText();
//1992
String yearOfEra = dateTime.yearOfEra().getAsShortText();
- dayOfWeek 星期几
- dayOfMonth 哪天
- dayOfYear 哪天(年)
- hourOfDay 几点
- monthOfYear 几月
- minuteOfHour 几分
- secondOfMinute 几秒
- secondOfDay 几秒(天)
- weekOfWeekyear 几周(年)
- yearOfEra 几公元年
网友评论