時區轉換

悉尼當前時間:2018/09/21 00:00:00  

悉尼時區:GMT+10  

時間戳(格林尼治時間):1537452000000  

北京時間:2018/09/20 22:00:00

根據當前時區的時間轉換爲時間戳方法:

public static Date convertTimeZoneToDate(String time, String dateFormat, String timeZone) {
        SimpleDateFormat bjSdf = new SimpleDateFormat(dateFormat);
        bjSdf.setTimeZone(TimeZone.getTimeZone(timeZone));
        try {
            Date result = bjSdf.parse(time);
            logger.info("time: {},dateFormat:{},timeZone:{},timestamp:{}", time, dateFormat, timeZone, result.getTime());
            return result;
        } catch (ParseException e) {
            logger.error("toTimeZone failed!time: {},dateFormat:{},timeZone:{},e:{}", time, dateFormat, timeZone, e);
            throw new RuntimeException("toTimeZone failed");
        }
    }

 

參考:

悉尼時區轉換:https://www.epochconverter.com/timezones?q=1537452000&tz=Australia%2FSydney

北京時間時間戳轉換:http://tool.chinaz.com/Tools/unixtime.aspx

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章