Reputation: 55
I need to convert this 20140815
into 15.08.2014
and into 15.08.2014 00:00:00
How do I do that, what opportunities are there in Java
Upvotes: 0
Views: 118
Reputation: 424983
Why bother with Dates... just use Strings:
String output = input.replaceAll("(....)(..)(..)", "$3.$2.$1");
or
String output = input.replaceAll("(....)(..)(..)", "$3.$2.$1 00:00:00");
Upvotes: 1
Reputation: 420921
You could use SimpleDateFormat
as follows
SimpleDateFormat inputFormat = new SimpleDateFormat("yyyyMMdd");
SimpleDateFormat outputFormat = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss");
Date date = inputFormat.parse("20140815");
String result = outputFormat.format(date);
Upvotes: 4