package com.sunsheen.dataimport;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.TimeZone;
public class Demo {
private static SimpleDateFormat format = new SimpleDateFormat(
"yyyy-MM-dd HH:mm:ss");
private static TimeZone zone = TimeZone.getTimeZone("Asia/Beijing");
public static void test() { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); Date date = null; try { date = sdf.parse(utcToTimeZoneDate("2014-07-31 01:00:00")); } catch (ParseException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } System.out.println(date + "------------------------------------------------"); } public static String utcToTimeZoneDate(String date) { Date timeStart; String beijing = null; try { timeStart = format.parse(date); format.setTimeZone(zone); beijing = format.format(timeStart); } catch (ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); } return beijing; } public static void main(String[] args) throws ParseException { test(); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); Date date = null; try { date = sdf.parse(utcToTimeZoneDate("2014-07-31 01:00:00")); } catch (ParseException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } System.out.println(date + "***********************************************"); }
}
互换的青春
陪伴而非守候
哆啦的时光机
慕仙森
相关分类