2016-06-23 44 views
-8

转换有没有像乔达时间任何实用程序下面的字符串转换成秒如何日期 - 时间以秒

例:字符串时间=“1个月内3天2 3点秒”

输出应该在几秒钟内

+1

一个月多久? – Leon

回答

0

我认为这个问题会在你有几个月的时候发挥作用。

“月份”太笼统了,是1月份还是2月份?该实用程序如何知道每个月将包含多少天?

此外,这一年还会在这里更改数据。

为了您的需要,您绝对可以使用乔达时间,但您将需要为适合的计算创建您自己的方法。

0

为什么不试试TimeUnit并避免重新发明轮子?

public static void main(String args[]) throws InterruptedException { 
    // "3 days 2 hours 3 seconds" 
    long secondsConverted = fooMEthod(3, 2, 3); 
    System.out.println("secondsConverted: " + secondsConverted); 
} 

private static long fooMEthod(int i, int j, int k) { 
    Long total = TimeUnit.DAYS.toSeconds(i) + TimeUnit.HOURS.toSeconds(j) + k; 
    return total; 
}