Java DateTime Format

 Java Date Time Format

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.TimeZone;
 

public class MyClass {
    public static void main(String args[]) {


//getting the current time for joining date
        Calendar cal = Calendar.getInstance();

        //milli sec
        // SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");

        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        sdf.setTimeZone(TimeZone.getTimeZone("Asia/Singapore"));
        String joiningDate = sdf.format(cal.getTime());
        System.out.println("Joining Date:  "+joiningDate);
    }
}

https://onlinegdb.com/rke_izk_X


http://tutorials.jenkov.com/java-date-time/java-util-timezone.html


SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
2018-09-07 05:31:34

SimpleDateFormat sdf = new SimpleDateFormat("dd-MMM-yy HH:mm:ss");
07-Sep-18 05:32:12

SimpleDateFormat sdf = new SimpleDateFormat("dd-MMM-yy HH:mm:ss a");
07-Sep-18 05:32:57 AM