Java Date GMT Format getTzToGmt(String dateStr, String dateFormat, String beforeTimeZone, String afterTimeZone)

Here you can find the source of getTzToGmt(String dateStr, String dateFormat, String beforeTimeZone, String afterTimeZone)

Description

get Tz To Gmt

License

Open Source License

Declaration

public static String getTzToGmt(String dateStr, String dateFormat, String beforeTimeZone, String afterTimeZone)
        throws ParseException 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

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

import java.util.Date;

import java.util.TimeZone;

public class Main {

    public static String getTzToGmt(String dateStr, String dateFormat, String beforeTimeZone, String afterTimeZone)
            throws ParseException {
        SimpleDateFormat sdfBefore = new SimpleDateFormat(dateFormat);
        sdfBefore.setTimeZone(TimeZone.getTimeZone(beforeTimeZone));
        SimpleDateFormat sdfAfter = new SimpleDateFormat(dateFormat);
        sdfAfter.setTimeZone(TimeZone.getTimeZone(afterTimeZone));
        Date date = stringToDate(dateStr, sdfBefore);
        String dateGmtEight = sdfAfter.format(date);
        return dateGmtEight;
    }/* ww w .j av a 2 s  .  c  om*/

    public static Date stringToDate(String dateStr, SimpleDateFormat dateFormat) throws ParseException {
        Date date = dateFormat.parse(dateStr);
        return date;
    }

    public static long parse(String date) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        try {
            return sdf.parse(date).getTime();
        } catch (ParseException e) {
            e.printStackTrace();
            return 0;
        }
    }

    public static long parse(String date, String pattern) {

        SimpleDateFormat sdft = new SimpleDateFormat(pattern);
        try {
            return sdft.parse(date).getTime();
        } catch (ParseException e) {
            e.printStackTrace();
            return 0;
        }
    }
}

Related

  1. getFormattedGMTDate(long timestamp)
  2. getNewGmtSimpleDateFormat(String format)
  3. getStringBaseGMT(Date date, String timezone)
  4. getThreadLocalGMTDateFormat(final String format)
  5. getTimeAndDateAtGMT()
  6. parseDate(String gmtTimeString)
  7. parseGMT(String gmtTime)
  8. parseGMTDatetime(String str)
  9. parseGMTTime(Long time, String format)