Joda-Time Formatter with a dateStyle and a timeStyle

后端 未结 2 707
被撕碎了的回忆
被撕碎了的回忆 2021-01-21 03:49

With java.text.DateFormat, it\'s possible to build a date formatter with a date and a time style :

DateFormat df = getDateTimeInstance(DateFormat.SHORT, DateForm         


        
相关标签:
2条回答
  • 2021-01-21 03:51

    Standard Formatting Built Into 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());
    

    Notice the DateTimeFormat.fullDateTime().

    Some other options for this include:

    • fullTime()
    • fullDate()
    • shortDateTime()
    • forStyle("MS") Indicates a Medium Date and a Short Time.
    • forStyle("S-") Indicates a Short Date and No Time.
    • ... etc ...

    The full listing can be found at:

    http://www.joda.org/joda-time/apidocs/org/joda/time/format/DateTimeFormat.html#forStyle(java.lang.String)

    Cheers,

    JP

    0 讨论(0)
  • 2021-01-21 04:05

    Use DateTimeFormat.forPattern() with a pattern that does what you want. For instance, DateTimeFormat.forPattern("YYYY-MM-dd HH:mm:ss");

    0 讨论(0)
提交回复
热议问题