Date java code example
Example 1: java date with T
SimpleDateFormat format = new SimpleDateFormat(
"yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", Locale.US);
format.setTimeZone(TimeZone.getTimeZone("UTC"));
Example 2: java date time
import java.time.format.DateTimeFormatter;
import java.time.LocalDateTime;
public class CurrentDateTimeExample1 {
public static void main(String[] args) {
DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy/MM/dd HH:mm:ss");
LocalDateTime now = LocalDateTime.now();
System.out.println(dtf.format(now));
}
}
Example 3: operation sur les dates java
dtEndDate.getTime() - dtStartDate.getTime()
Example 4: dates in java 8
LocalDateTime.parse("2015-02-20T06:30:00");
Example 5: dates in java 8
LocalDate.of(2015, 02, 20);
LocalDate.parse("2015-02-20");