栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

如何在Joda-Time中正确获取当前日期和时间?

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

如何在Joda-Time中正确获取当前日期和时间?

这是Joda Time的伪代码,可能对您有用。

import org.joda.time.*;import org.joda.time.format.DateTimeFormat;import org.joda.time.format.DateTimeFormatter;public class JodaTimeExample {    public static void main(String[] sm) {        DateTimeFormatter dateFormat = DateTimeFormat     .forPattern("G,C,Y,x,w,e,E,Y,D,M,d,a,K,h,H,k,m,s,S,z,Z");        String dob = "2002-01-15";        LocalTime localTime = new LocalTime();        LocalDate localDate = new LocalDate();        DateTime dateTime = new DateTime();        LocalDateTime localDateTime = new LocalDateTime();        DateTimeZone dateTimeZone = DateTimeZone.getDefault();        System.out     .println("dateFormatr : " + dateFormat.print(localDateTime));        System.out.println("LocalTime : " + localTime.toString());        System.out.println("localDate : " + localDate.toString());        System.out.println("dateTime : " + dateTime.toString());        System.out.println("localDateTime : " + localDateTime.toString());        System.out.println("DateTimeZone : " + dateTimeZone.toString());        System.out.println("Year Difference : "     + Years.yearsBetween(DateTime.parse(dob), dateTime).getYears());        System.out.println("Month Difference : "     + Months.monthsBetween(DateTime.parse(dob), dateTime)  .getMonths());    }}

DateTimeFormat格式器的链接

乔达时间API

我希望这能帮到您。如果您有任何疑问,请告诉我。

PS:感谢Sumit Arora提供的输出。

dateFormatr : AD,20,2016,2016,26,2,Tue,2016,180,6,28,PM,8,8,20,20,25,20,2,‌​, LocalTime : 20:25:17.308 localDate : 2016-06-28 dateTime : 2016-06-28T20:25:18.872+05:30 localDateTime : 2016-06-28T20:25:20.260 DateTimeZone : Asia/Kolkata Year Difference : 14 Month Difference : 173


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/454788.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号