Last active
May 24, 2016 15:44
-
-
Save lizettepreiss/1f26f13648d4f8555452744b5fd12576 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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