Saturday, 26 March 2016

How to convert UTC time stamp to PST time.

Here I am going to write how to convert UTC time zone to PST time zone.

private void convertUtcTimeToPstTimeZone() {
        String utcTime = "2016-08-14T22:56:02.038Z";
        SimpleDateFormat utcFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", Locale.getDefault());
        utcFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
        try {
            Date date = utcFormat.parse(utcTime);
            DateFormat pstFormat = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss", Locale.getDefault());
            pstFormat.setTimeZone(TimeZone.getTimeZone("PST"));
            System.out.println(pstFormat.format(date));
        } catch (ParseException e) {
            e.printStackTrace();
        }

    }

Result is: 14-08-2016 22:56:02

No comments:

Post a Comment