Skip to content

Instantly share code, notes, and snippets.

@fty4
Created December 15, 2016 16:10
Show Gist options
  • Save fty4/39377def27e51a709508bc22c961979f to your computer and use it in GitHub Desktop.
Save fty4/39377def27e51a709508bc22c961979f to your computer and use it in GitHub Desktop.
Shows how to get current Time from GregorianCalendar-Type
Date d = new Date();
Calendar cal = Calendar.getInstance();
cal.setTime(d);
GregorianCalendar c = new GregorianCalendar(
cal.get(Calendar.YEAR),
cal.get(Calendar.MONTH),
cal.get(Calendar.DAY_OF_MONTH),
cal.get(Calendar.HOUR_OF_DAY),
cal.get(Calendar.MINUTE),
cal.get(Calendar.SECOND));
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd HH mm ss");
System.out.println(sdf.format(c.getTime()));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment