Java中的时间常量? [英] Time consts in Java?

查看:71
本文介绍了Java中的时间常量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有一个Java程序包,其中包括每分钟/小时/天/年的所有烦人的时间常数,例如
毫秒/秒/分钟?我不愿意重复这样的事情。

Is there a Java package with all the annoying time constants like milliseconds/seconds/minutes in a minute/hour/day/year? I'd hate to duplicate something like that.

推荐答案

Joda-Time 包含诸如天数,其中包含诸如 toStandardSeconds()。因此,您可以这样写:

Joda-Time contains classes such as Days, which contain methods such as toStandardSeconds(). So you can write:

int seconds = Days.ONE.toStandardSeconds();

虽然看起来有些冗长,也许仅对更复杂的情况(例如leap年)有用

although it seems a little verbose, and perhaps is only useful for more complex scenarios such as leap years etc.

这篇关于Java中的时间常量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆