kibibyte
kibibyte

Reputation: 3037

How do I convert a String representation of time into Unix time?

I need to convert timestamps of the form yy-mm-dd-hh-mm-ss to a long that represents Unix time. Is there a class in Java's standard library that allows me to do this very easily? Or will I have to code the conversion algorithm myself?

I'm doing this on Android API level 7, in case that environment cuts off some of the necessary Java libraries.

Upvotes: 1

Views: 124

Answers (1)

Jeffrey
Jeffrey

Reputation: 44808

You'll have to parse your timestamp (String.split() may prove useful here) to create a Calendar. From here you can call Calandar.getTimeInMillis() to get the UTC time.

Upvotes: 1

Related Questions