java.util.date to String using DateTimeFormatter

前端 未结 5 2069
抹茶落季
抹茶落季 2021-02-12 12:08

How can I convert a java.util.Date to String using

 DateTimeFormatter dateTimeFormatter = DateTimeFormat.forPattern(\"yyyy-MM-dd\'T\'H         


        
5条回答
  •  难免孤独
    2021-02-12 12:52

    You can use the joda time formatter class:

    import org.joda.time.DateTime;
    import org.joda.time.DateTimeZone;
    import org.joda.time.format.DateTimeFormat;
    import org.joda.time.format.DateTimeFormatter;
    # conflict with import java.time.format.DateTimeFormatter;
    
    final DateTimeFormatter formatter = DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ss")
                .withZone(DateTimeZone.UTC);
    
        System.out.println(DateTime.now().toString(formatter));
    

提交回复
热议问题