java取时间戳,java生成时间戳的方法

发布时间:2023-01-08

本文目录一览:

  1. java怎么获取19位时间戳
  2. java中14位时间戳怎么获取
  3. Java获取时间戳精确到年月日时

java怎么获取19位时间戳

public Long getToday(){
    DateTime now = new DateTime();
    return new DateTime(now.getYear(), now.getMonthOfYear(), now.getDayOfMonth(), 0, 0, 0, 0).getMillis();
}
public Long getTomorrow(){
    DateTime now = new DateTime();
    return new DateTime(now.getYear(), now.getMonthOfYear(), now.getDayOfMonth(), 0, 0, 0, 0).plusDays(1).getMillis();
}

java中14位时间戳怎么获取

按你描述,应该想要的是Unix时间戳,即当前时间到1970年1月1日0:0:0的毫秒数据。 在java里面Data类型可以直接用API获取。

SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss")
String value=20150704000000;
df.parse(value).getTime(); // 就是你想要的时间戳。

具体可以查看Date类型的API 以及

Java获取时间戳精确到年月日时

其实系统默认的都是毫秒数的时间戳, 所以你想要的2017-01-16 17:00:00不是提取的, 而是格式化的

new SimpleDateFormat("yyyy-MM-dd HH:00:00").format(System.currentTimeMillis());