get Simple Date Format AMPM - Android java.util

Android examples for java.util:Date Format

Description

get Simple Date Format AMPM

Demo Code


//package com.java2s;

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

import java.util.Locale;
import java.util.TimeZone;
import android.text.TextUtils;

public class Main {
    private static SimpleDateFormat sdf;
    private static Calendar calendar;

    public static String getSimpleDateFormatAMPM(String time) {

        String mTime = "";

        mTime = getNewSimpleDateFormat("yyyy D a hh? mm?", time);

        return mTime;
    }//from  w  w w  .jav  a 2  s .com

    public static String getNewSimpleDateFormat(String pattern, String time) {

        String mTime = "";

        if (TextUtils.isEmpty(pattern) || TextUtils.isEmpty(time))
            return mTime;

        sdf = new SimpleDateFormat(pattern, Locale.KOREA);
        sdf.setTimeZone(TimeZone.getTimeZone("Asia/Seoul"));

        calendar = Calendar.getInstance();
        calendar.setTimeZone(sdf.getTimeZone());
        calendar.setTimeInMillis(Long.parseLong(time) * 1000L);

        mTime = sdf.format(calendar.getTime());
        return mTime;
    }
}

Related Tutorials