Joda-Time

 

根据Millis计算minutes:

demo:

import org.joda.time.Interval;
import org.joda.time.LocalDateTime;

/**
 * Created by tang.cheng on 2017/5/19.
 */
public class Test {

    public static void main(String[] args) {
        long startTime = LocalDateTime.now().toDate().getTime();
        int millis = 1234567890;
        System.out.println("plus millis:" + millis);
        long endTime = LocalDateTime.now().plusMillis(millis).toDate().getTime();
        System.out.println("startTime:" + startTime + " \nendTime:" + endTime);

        long totalTime = endTime - startTime;
        System.out.println("TotalMillis: " + totalTime);
        long l = totalTime / 60 / 1000;
        System.out.println("Total minutes:" + l + (millis == totalTime ? "没有精度损失" : "有精度损失"));

        Interval interval = new Interval(startTime, endTime);
        long standardMinutes = interval.toDuration().getStandardMinutes();
        System.out.println("Total minutes:" + standardMinutes);
    }
}

http://1985wanggang.blog.163.com/blog/static/7763833201371341545546/

http://www.yihaomen.com/article/java/405.htm

 

withMillis

public DateTime withMillis(long newMillis)
Returns a copy of this datetime with different millis.

The returned object will be either be a new instance or this. Only the millis will change, the chronology and time zone are kept.

Parameters:
newMillis - the new millis, from 1970-01-01T00:00:00Z
Returns:
a copy of this datetime with different millis

http://www.joda.org/joda-time/

 

posted @ 2016-09-25 11:26  沧海一滴  阅读(303)  评论(0编辑  收藏  举报