Android Time Format getTimeString(Date utcDate)

Here you can find the source of getTimeString(Date utcDate)

Description

get Time String

Declaration

public static String getTimeString(Date utcDate) 

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 {/*from   www  . java 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. timeLongToHhmm(long timeMillis, DateFormat df)
  2. toModifiedTimeString(Date modified)
  3. convertDateTime(String date)
  4. convertDateTime(long date)
  5. getTimeStr(long time)
  6. getTimeString(String dateString)
  7. getTimeString(String utcTimeString)
  8. dateTimeToXSDate(Date date)
  9. dateTimeToXSDateTime(Date date)