format Date by time zone GMT-0:00 - Android java.util

Android examples for java.util:Timezone

Description

format Date by time zone GMT-0:00

Demo Code

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;
import java.util.TimeZone;

public class Main{

    public static String formatDate(Date date, String formatString) {
        String result = "";
        SimpleDateFormat sdf = new SimpleDateFormat(formatString,
                Locale.getDefault());
        sdf.setTimeZone(TimeZone.getTimeZone("GMT-0:00"));
        result = sdf.format(date);/*ww w .j  a va2s .c  o  m*/
        return result;
    }
    public static String formatDate(long milliseconds, String formatString) {
        String result = "";
        Calendar cal = Calendar.getInstance();
        cal.setTimeInMillis(milliseconds);
        SimpleDateFormat sdf = new SimpleDateFormat(formatString,
                Locale.getDefault());
        sdf.setTimeZone(TimeZone.getTimeZone("GMT-0:00"));
        result = sdf.format(cal.getTime());
        return result;
    }

}

Related Tutorials