Home > Java > javaTutorial > body text

Java Example - Convert timestamp to time

黄舟
Release: 2017-02-18 09:54:18
Original
1817 people have browsed it

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);
   }}
Copy after login

The output of the above code is:

2015-03-28
Copy after login

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)!


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!