Java tutorial
//package com.java2s; /* * Copyright 2012 sohu.com All right reserved. This software is the * confidential and proprietary information of sohu.com ("Confidential * Information"). You shall not disclose such Confidential Information and shall * use it only in accordance with the terms of the license agreement you entered * into with sohu.com. */ import java.text.SimpleDateFormat; import java.util.Date; import java.util.TimeZone; public class Main { public static String getDate(long time, String format) { TimeZone tz = TimeZone.getTimeZone("Asia/Shanghai"); TimeZone.setDefault(tz); String datetime = ""; Date date = new Date(time); SimpleDateFormat sdf = new SimpleDateFormat(format); datetime = sdf.format(date); return datetime; } }