Home >Java >javaTutorial >Java Example - Convert timestamp to time
The following example demonstrates how to use the format() method of the SimpleDateFormat class to convert a timestamp into a time:
/*
author by w3cschool.cc
文件名:Main.java
*/import java.text.SimpleDateFormat;import java.util.Date;public class Main{
public static void main(String[] args){
Long timeStamp = System.currentTimeMillis(); //获取当前时间戳
SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
String sd = sdf.format(new Date(Long.parseLong(String.valueOf(timeStamp)))); // 时间戳转换成时间
System.out.println(sd);
}}
The output of the above code is:
2015-03-28
The above is the Java example - the content of converting timestamp into time. For more related content, please pay attention to the PHP Chinese website (www.php.cn)!