时间戳和日期的互相转换

public class TimeStampToDate {
	public static void main(String[] args) {
		TimeStampToDate tsd = new TimeStampToDate();
		tsd.dateToTime(1319095800);
		DateFormat format = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
		Date date = null;
		try {
			date = format.parse("2011-10-20 15:30:00");
		} catch (ParseException e) {
			e.printStackTrace();
		}
		tsd.timeToDate(date);
	}
	
	public void dateToTime(long time) {
		String str = String.format("%tF %<tT", time * 1000L);
		System.out.println(str);
	}


	public void timeToDate(Date date) {
		System.out.println(Long.toString(date.getTime()));
	}
}


你可能感兴趣的:(时间戳和日期的互相转换)