Skip to content

Instantly share code, notes, and snippets.

@oflarcade
Created October 25, 2018 15:23
Show Gist options
  • Save oflarcade/3945925ad9f2d885bcf0ce3c5d977691 to your computer and use it in GitHub Desktop.
Save oflarcade/3945925ad9f2d885bcf0ce3c5d977691 to your computer and use it in GitHub Desktop.
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package datetest;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Calendar;
import java.util.Date;
/**
*
* @author oflcad
*/
public class DateTest {
private static final DateFormat sdf = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
private static final DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy/MM/dd HH:mm:ss");
public static void main(String[] args) {
Date date = new Date();
System.out.println(sdf.format(date));
Calendar cal = Calendar.getInstance();
System.out.println(sdf.format(cal.getTime()));
LocalDateTime now = LocalDateTime.now();
System.out.println(dtf.format(now));
LocalDate localDate = LocalDate.now();
System.out.println(DateTimeFormatter.ofPattern("yyy/MM/dd").format(localDate));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment