Hello i am very new to android Development , working on a Android Code right now ,I need to Get the current date and time in this Format
YYYY-MM-DDTHH:MM.000z
For Example 2013-11-26T03:16:00.000Z
Any Help will be really Appreciated
Hello i am very new to android Development , working on a Android Code right now ,I need to Get the current date and time in this Format
YYYY-MM-DDTHH:MM.000z
For Example 2013-11-26T03:16:00.000Z
Any Help will be really Appreciated
You are asking for the ISO 8601 format set to UTC time zone.
Instant.now().toString()
2018-01-25T22:50:24.702645Z
The java.time classes use the standard ISO 8601 formats by default when parsing or generating strings.
The Instant
class represents a moment on the timeline in UTC with a resolution of nanoseconds (up to nine (9) digits of a decimal fraction).
Get the current moment in UTC:
Instant instant = Instant.now() ;
To generate a string in standard ISO 8601 format:
String output = instant.toString() ; // Generate string in standard format.
Going the other direction, parsing such a string.
Instant instant = Instant.parse( "2013-11-26T03:16:00.000Z" );
Search Stack Overflow for much discussion of java.time classes such as ZoneId
, ZonedDateTime
, and OffsetDateTime
.
Update: The Joda-Time project is now in maintenance mode, with the team advising migration to the java.time classes.
ISO 8601 formats are the default for the Joda-Time 2.3 library.
System.out.println( "Now: " + new org.joda.time.DateTime( org.joda.time.DateTimeZone.UTC ) );
When run…
Now: 2013-11-26T20:25:12.014Z
The java.time framework is built into Java 8 and later. These classes supplant the troublesome old legacy date-time classes such as java.util.Date
, Calendar
, & SimpleDateFormat
.
The Joda-Time project, now in maintenance mode, advises migration to the java.time classes.
To learn more, see the Oracle Tutorial. And search Stack Overflow for many examples and explanations. Specification is JSR 310.
Where to obtain the java.time classes?
The ThreeTen-Extra project extends java.time with additional classes. This project is a proving ground for possible future additions to java.time. You may find some useful classes here such as Interval
, YearWeek
, YearQuarter
, and more.
There is documentation readily available for Android's SimpleDateFormat class at:
http://developer.android.com/reference/java/text/SimpleDateFormat.html
Also appears to have been answered before. Among other places.
Use SimpleDateFormat sd= new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");