-1

Can anyone help me to print date in the format below

 2016-11-22T14:52:17+05:30

without using JODA Time and apache fast date format.

aurelius
  • 3,946
  • 7
  • 40
  • 73
Rajendra Gupta
  • 381
  • 1
  • 16

1 Answers1

1

Use SimpleDateFormat:

System.out.println(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ").format(new Date()));

or in Java8 DateTimeFormatter:

System.out.println(DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ssZ").format(ZonedDateTime.now()));      
Jens
  • 67,715
  • 15
  • 98
  • 113