Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to print DateTime without milliseconds [duplicate]

I am reading data from a file and will need to serialize it out elsewhere after some computation. How can I get the following to print without milliseconds so that the string that is passed to DateTime.parse and what is outputted are identical?

System.out.println(DateTime.parse("2015-06-06T01:51:49-06:00").toString())

2015-06-06T01:51:49.000-06:00

like image 826
user782220 Avatar asked Nov 19 '15 07:11

user782220


2 Answers

DateTimeFormatter formatter = new DateTimeFormatterBuilder().append(ISODateTimeFormat.dateTimeNoMillis()).toFormatter().withOffsetParsed();
formatter.print(DateTime.parse("2015-06-06T01:51:49-06:00"))
like image 131
user782220 Avatar answered Nov 01 '22 01:11

user782220


You can use the joda time formatter:

DateTime dt = new DateTime();
DateTimeFormatter fmt = DateTimeFormat.forPattern("MMMM, yyyy");
String str = fmt.print(dt);
like image 23
ΦXocę 웃 Пepeúpa ツ Avatar answered Nov 01 '22 01:11

ΦXocę 웃 Пepeúpa ツ