parse string to Date by timezone - Android java.util

Android examples for java.util:Date Parse

Description

parse string to Date by timezone

Demo Code

import android.annotation.SuppressLint;
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 Date parse(String format, String date, TimeZone timeZone)
            throws ParseException {
        SimpleDateFormat df = new SimpleDateFormat(format, Locale.ENGLISH);
        df.setTimeZone(timeZone);/*from  www.j av  a 2s. c om*/
        return df.parse(date);
    }
    public static Date parse(String format, String date)
            throws ParseException {
        return parse(format, date, TimeZone.getTimeZone("UTC"));
    }

}

Related Tutorials