Skip to content

Commit f4844c2

Browse files
author
Tanechka
committed
Lesson08 DateTime api
1 parent 8ba1997 commit f4844c2

2 files changed

Lines changed: 52 additions & 0 deletions

File tree

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package ru.javawebinar.basejava;
2+
3+
import java.text.SimpleDateFormat;
4+
import java.time.LocalDate;
5+
import java.time.LocalDateTime;
6+
import java.time.LocalTime;
7+
import java.time.format.DateTimeFormatter;
8+
import java.util.Calendar;
9+
import java.util.Date;
10+
import java.util.TimeZone;
11+
12+
/**
13+
* gkislin
14+
* 20.07.2016
15+
*/
16+
public class MainDate {
17+
public static void main(String[] args) {
18+
long start = System.currentTimeMillis();
19+
Date date = new Date();
20+
System.out.println(date);
21+
System.out.println(System.currentTimeMillis() - start);
22+
Calendar cal = Calendar.getInstance();
23+
cal.setTimeZone(TimeZone.getTimeZone("America/Los_Angeles"));
24+
System.out.println(cal.getTime());
25+
26+
LocalDate ld = LocalDate.now();
27+
LocalTime lt = LocalTime.now();
28+
LocalDateTime ldt = LocalDateTime.of(ld, lt);
29+
System.out.println(ldt);
30+
31+
32+
SimpleDateFormat sdf = new SimpleDateFormat("YY/MM/dd");
33+
System.out.println(sdf.format(date));
34+
35+
DateTimeFormatter dtf = DateTimeFormatter.ofPattern("YY/MM/dd");
36+
System.out.println(dtf.format(ldt));
37+
}
38+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package ru.javawebinar.basejava.util;
2+
3+
import java.time.LocalDate;
4+
import java.time.Month;
5+
6+
/**
7+
* gkislin
8+
* 20.07.2016
9+
*/
10+
public class DateUtil {
11+
public static LocalDate of(int year, Month month) {
12+
return LocalDate.of(year, month, 1);
13+
}
14+
}

0 commit comments

Comments
 (0)