【问题标题】:How to get year, month,day from given timestamp like "1459233289187" [duplicate]如何从给定的时间戳中获取年、月、日,如“1459233289187”[重复]
【发布时间】:2016-03-29 06:58:26
【问题描述】:

我正在根据系统时间计算时间戳

System.currentTimeMillis()

在java中。

稍后,我想从这个时间戳计算年、月和日期。 有什么办法吗?

【问题讨论】:

  • new Date(System.currentTimeMillis())
  • 您是否尝试过先搜索类似这样的另一个问题?
  • 您需要针对特定​​时区进行计算。来自时间戳的年份、月份或月份中的日期有多个值。

标签: java


【解决方案1】:
Calendar cal = Calendar.getInstance();
cal.setTimeInMillis(timestamp);
int year = cal.get(Calendar.YEAR);

【讨论】:

    猜你喜欢
    • 2013-07-26
    • 2012-03-17
    • 2019-12-12
    • 1970-01-01
    • 2016-05-20
    • 2023-03-14
    • 2013-01-09
    • 2011-02-23
    • 2015-12-31
    相关资源
    最近更新 更多