Converting date and time to a string in Java
Forums:
Date now = new Date();
DateFormat df = new SimpleDateFormat("M/dd/YY h:mm a");
String shortStyle = df.format(now);
//shortStyle is "10/16/15 3:25 PM"
df = new SimpleDateFormat("yyyy-MM-dd");
String customStyle = df.format(now);
//customStyle is 2015-10-16
- Log in to post comments