java------3.时间戳

Posted 奇思妙想的香菜

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了java------3.时间戳相关的知识,希望对你有一定的参考价值。

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;


public class Test {

    public static void main(String[] args) throws ParseException {
        //当前时间
        Date now = new Date(); 
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
        //Date转换成String 
        System.out.println(df.format(now));

        //String转换成Date
        Date daTime=df.parse(df.format(now));
        long longTime;
        //年月日转换成时间戳
        longTime = daTime.getTime();
        System.out.println(longTime);
        
        //时间戳增加24小时转换成年月日
        long lt = longTime+24*3600*1000;
        Date date = new Date(lt);
        String res = df.format(date);
        System.out.println(res);
    }
}

 

以上是关于java------3.时间戳的主要内容,如果未能解决你的问题,请参考以下文章

java------3.时间戳

MPEG DASH 部分片段

时间戳的休眠搜索查询返回空列表

各个品牌的代码签名中都有时间戳,是干啥用的?

MySQL中日期和时间戳互相转换的函数和方法

代码签名中的时间戳有啥用?