I need to convert date/time in a text file into number of minutes elapsed since unix epoch (i.e., January 1st, 1970):
e.g. 2006-01-01 07:14:38.000 into 18934874
I'm using Java to parse the file. thanks
you can use the class SimpleDateFormat to parse the time. For example
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd kk:mm:ss.SSS");
Date date = sdf.parse("2006-01-01 07:14:38.000");
long timeInMillisSinceEpoch = date.getTime();
long timeInMinutesSinceEpoch = timeInMillisSinceEpoch / TimeUnit.MILLISECONDS.toMinutes(timeInMillisSinceEpoch);
1) A few minutes ago I realized that I've used the wrong pattern for milliseconds (used 's' instead of 'S'). Sorry for the mistake. 2) Added suggestion from @superfav
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With