-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJodaTimeExamples.java
More file actions
31 lines (22 loc) · 1.07 KB
/
JodaTimeExamples.java
File metadata and controls
31 lines (22 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package datereflection;
import org.joda.time.DateTime;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;
public class JodaTimeExamples {
public static void main(String[] args) {
DateTime dt = new DateTime(); // Joda Date
System.out.println("Date:" + dt.toDate()); // Java Date
int month = dt.getMonthOfYear();
System.out.println("MonthOfYear: " + month);
DateTime.Property pDoW = dt.dayOfWeek();// Monday:1 to Sunday:7
System.out.println("dayOfWeek: " + pDoW.getAsText()); // print:Monday/Tuesday
System.out.println("getDayOfMonth: " + dt.getDayOfMonth());
int maxDay = dt.dayOfMonth().getMaximumValue();
System.out.println("Last day of this month: " + maxDay + " day");
boolean leapYear = dt.yearOfEra().isLeap();
System.out.println("Leap Year: " + leapYear);
DateTime datePlus20 = dt.plusDays(20);
DateTimeFormatter formattedDate = DateTimeFormat.forPattern("dd/MM/yyyy");
System.out.println(dt.toString(formattedDate) + " + 20 day = " + datePlus20.toString(formattedDate));
}
}