Reputation: 64834
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
Upvotes: 9
Views: 28937
Reputation: 29927
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 = TimeUnit.MILLISECONDS.toMinutes(timeInMillisSinceEpoch);
Upvotes: 28