---
title: "时间戳转换"
author: "arpenker"
date: "2016-05-20T17:27:39Z"
tags: []
categories: ["编程语言"]
slug: "untitled"
draft: false
lastmod: "2016-05-20T17:27:39Z"
id: 2299602
url: "https://arpenker.iteye.com/blog/2299602"
---

package test;

import java.util.Date;

public class Test {
	public static void main(String args) throws Exception {
		t1();
		t2();
	}
	
	/**
	 * 日期对象转换为时间戳
	 */
	public static void t1(){
		Date date = new Date();
		long times = date.getTime();
		System.out.println(times);
		//输出结果：1386665346113
	}
	
	/**
	 * 时间戳转换为日期对象
	 */
	public static void t2(){
		long times = 1386665666777L;
		Date date = new Date(times);
		System.out.println(date);
		//输出结果：Tue Dec 10 16:54:26 CST 2013
	}
}