Java SimpleDateFormat - input and output are different

I get a date string - "2012-04-19 20:51:06". Then I get a millimeter of time using 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, milliTime is 1334839866000L

However, when I convert mmiTime to String date format. 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 is the problem?

+3
source share
1 answer

Try using HH for the hour component, not hh.

+8
source

All Articles