首页 > 编程知识 正文

java字符串转date,java date转换成string

时间:2023-05-04 21:01:19 阅读:145867 作者:215

howcaniconvertajava.util.datetostringusing

The Date object which i get is passed

日期新=新日期(日期;

If you are using Java 8,youshouldnotusejava.util.dateinthefirstplace (unlessyoureceivethedateobjectfromalibrarythatyouhaveno

In any case,youcanconvertadatetoajava.time.instant using 3360

日期日期=;

Instant instant=date.toInstant (;

sinceyouareonlyinterestedinthedateandtime,withouttimezoneinformation,Iassumeeverythingisutc,youcanconverttthatinstttto

localdatetimeldt=instant.at offset (区域offset.utc ).toLocalDateTime );

Finally you can print it with:

notethatifyoudon ' tprovideaformatter,calling ldt.tostringgivesoutputinstandardiso 8601 format (including milliseconds )-that

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。