Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Apache License 

import android.text.TextUtils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

import java.util.Locale;

public class Main {

    public static String convertUtc2LocalPro(String utcTime) {
        if (TextUtils.isEmpty(utcTime)) {
            return "";
        }
        // 2014-10-24T02:58:05.932Z
        SimpleDateFormat utcFormatter, localFormatter;
        utcFormatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", Locale.ENGLISH);
        Date date;
        Calendar cal = Calendar.getInstance();
        try {
            date = utcFormatter.parse(utcTime);
            cal.setTime(date);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        cal.add(Calendar.HOUR_OF_DAY, +8);
        date = cal.getTime();
        localFormatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.CHINA);
        return localFormatter.format(date);
    }
}