本文介紹了帶有 dateStyle 和 timeStyle 的 Joda-Time 格式化程序的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
使用 java.text.DateFormat
,可以構建具有日期和時間樣式的日期格式化程序:
With java.text.DateFormat
, it's possible to build a date formatter with a date and a time style :
DateFormat df = getDateTimeInstance(DateFormat.SHORT, DateFormat.LONG);
system.out.println(df.format(new Date()));
是否可以使用與 Joda-Time 類似的東西?
Is it possible to use something similar with Joda-Time ?
推薦答案
JodaTime 內置了一系列標準的日期和時間格式.
There's a bunch of standard Date and Time formats built right into JodaTime.
這是我使用的一個示例:
Here's an example of one that I use:
DateTime dateTime = DateTime.now(DateTimeZone.UTC);
String formattedDateTime = dateTime.toString(DateTimeFormat.fullDateTime());
注意 DateTimeFormat.fullDateTime()
.
其他一些選項包括:
fullTime()
fullDate()
shortDateTime()
forStyle("MS")
表示中日期和短時間.forStyle("S-")
表示短日期和無時間.- ...等等...
fullTime()
fullDate()
shortDateTime()
forStyle("MS")
Indicates a Medium Date and a Short Time.forStyle("S-")
Indicates a Short Date and No Time.- ... etc ...
http://www.joda.org/joda-time/apidocs/org/joda/time/format/DateTimeFormat.html#forStyle(java.lang.String)
干杯,
日本
這篇關于帶有 dateStyle 和 timeStyle 的 Joda-Time 格式化程序的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!