Goleo8
Goleo8

Reputation: 135

Java SimpleDateFormat -- input and output is different

I get the date string --"2012-04-19 20:51:06". Then I get the milli time by SimpleDateFormat.

    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
    Date d=sdf.parse("2012-04-19 20:51:06");
    long milliTime=d.getTime()

Then the milliTime is 1334839866000L

However when I convert milliTime to date format String. The result is "2012-04-19 08:51:06"

    long time = 1334839866000L;
    Date date = new Date(time);

    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
    String t = sdf.format(date);

What's the problem?

Upvotes: 3

Views: 1620

Answers (1)

pilotcam
pilotcam

Reputation: 1749

Try using HH for the hour component rather than hh.

Upvotes: 8

Related Questions