Date to UTC format Java

I have such a string 2013-10-22t01:37:56 I need to change this string to UTC date format, such as mm / DD / yyyy KK: mm: SS A. I've tried some code, but it doesn't return UTC datetime

My code is

String[] time = itsAlarmDttm.split("T");
        String aFormatDate = time[0]+ " "+time[1];
        String aRevisedDate = null;
        try {
            final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            final Date dateObj = sdf.parse(aFormatDate);
            aRevisedDate = new SimpleDateFormat("MM/dd/yyyy KK:mm:ss a").format(dateObj);
            System.out.println(aRevisedDate);
        } catch (ParseException e) {
            itsLogger.error("Error occured in Parsing the Data Time Object:  " +e.getMessage());
        } catch (Exception e) {
            itsLogger.error("Error occured in Data Time Objecct:  " +e.getMessage());
        }

The output I get is mm / DD / yyyy KK: mm: ss a format But not in UTC time format How to solve this problem?

Solution

Try formatting the date with a Z or Z time zone marker:

new SimpleDateFormat("MM/dd/yyyy KK:mm:ss a Z").format(dateObj);
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>