Java UTC Date utcTolocal(String utc)

Here you can find the source of utcTolocal(String utc)

Description

utc Tolocal

License

Open Source License

Declaration

public static String utcTolocal(String utc) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;

import java.util.Date;

import java.util.TimeZone;

public class Main {
    static SimpleDateFormat dateFormatter = new SimpleDateFormat("E, MMMM d, yyyy HH:mm:ss, z");

    public static String utcTolocal(String utc) {
        if (utc == null)
            return "NULL";

        DateFormat utcFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");

        utcFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
        Date date = null;//from  w  w  w  . j av  a 2s .  c  o  m

        try {
            date = utcFormat.parse(utc);
        } catch (ParseException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            return utc;
        }
        return formatDate(date);
    }

    public static String formatDate(Date d) {
        return dateFormatter.format(d);
    }
}

Related

  1. utcTime(Locale locale)
  2. utcTimestamp(Date date)
  3. utcTimeToString(String dateStr)
  4. utcToDate(String utcTimestamp)
  5. utcToLocal(Date date)