Android Time Format getTimeString(String utcTimeString)

Here you can find the source of getTimeString(String utcTimeString)

Description

get Time String

Declaration

public static String getTimeString(String utcTimeString) 

Method Source Code

//package com.java2s;

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

import java.util.Date;

import java.util.Locale;

import java.util.TimeZone;

public class Main {
    public static String getTimeString(String utcTimeString) {

        try {/* w ww. ja va 2  s  .  c  om*/
            SimpleDateFormat sdf = new SimpleDateFormat(
                    "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", Locale.US);
            sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
            Date date = sdf.parse(utcTimeString);
            sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.CHINA);
            return sdf.format(date.getTime());
        } catch (ParseException e) {
            e.printStackTrace();
            return null;
        }

    }

    public static String getTimeString(Date utcDate) {
        if (utcDate.getTime() == 0) {
            return "";
        }

        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm",
                Locale.CHINA);
        return sdf.format(utcDate.getTime());
    }
}

Related

  1. convertDateTime(String date)
  2. convertDateTime(long date)
  3. getTimeStr(long time)
  4. getTimeString(Date utcDate)
  5. getTimeString(String dateString)
  6. dateTimeToXSDate(Date date)
  7. dateTimeToXSDateTime(Date date)