2

Unix timestamp is 1334672401.

long t = Long.parseLong(map.get("timestamp").toString());   
SimpleDateFormat formatter = new SimpleDateFormat("EEE MMM dd, ''yy, hh:mma");
Date time = new Date(t*1000);
Date date = formatter.parse(time.toString());

I'm trying to convert a unix timestamp into a Date object in the format to something similar to Thu Apr 17 2012, 16:25 but I keep getting an unparseable date error and I'm not sure whats wrong exactly?

1 Answer 1

4

You have the Date object already when you did this:

Date time = new Date(t*1000);

Use the formatter to format your string output, like this:

System.out.println(formatter.format(time));
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.