Skip to content

Instantly share code, notes, and snippets.

@lizettepreiss
Last active May 24, 2016 15:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lizettepreiss/1f26f13648d4f8555452744b5fd12576 to your computer and use it in GitHub Desktop.
Save lizettepreiss/1f26f13648d4f8555452744b5fd12576 to your computer and use it in GitHub Desktop.
DateFormat df = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
Date today = Calendar.getInstance().getTime();
String reportDate = df.format(today);
//------- long to Date -------
The Date constructor (click the link!) accepts the time as long in milliseconds, not seconds.
You need to multiply it by 1000 and make sure that you supply it as long.
Date d = new Date(1220227200L * 1000);
//-------------- Another Example: -------------------------------------
String DATE_FORMAT_NOW = "yyyy-MM-dd";
Date date = new Date();
SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT_NOW);
String stringDate = sdf.format(date );
try {
Date date2 = sdf.parse(stringDate);
long milliseconds = date2.getTime();
} catch(Exception e){
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment