What Is This Date Format? 2011-08-12T20:17:46.384Z

What is this date format? 2011-08-12T20:17:46.384Z

The T is just a literal to separate the date from the time, and the Z means "zero hour offset" also known as "Zulu time" (UTC). If your strings always have a "Z" you can use:

SimpleDateFormat format = new SimpleDateFormat(
"yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", Locale.US);
format.setTimeZone(TimeZone.getTimeZone("UTC"));

Or using Joda Time, you can use ISODateTimeFormat.dateTime().

how do I read this date-time format 2019-12-17T17:23:49.782Z?

This is iso 8061, so you can try like this:

$date = '2019-12-17T17:23:49.782Z';
$date = date('Y-m-d', strtotime(substr($date,0,10)));
echo $date;

What type of date string is this? `20210713T015433.354Z`

The date format provided is ISO 8601. Maybe you want to try the following to get a Date object:

new Date(Date.UTC(2021, 7, 13, 1, 54, 33, 354))

As pointed in this SO answer.

What date format is this date 2021-08-03T04:10:07.502-0700 ?


tl;dr

Diagram of your input string, containing a date, a separator, a time-of-day, and an offset-from-UTC.

2021-08-03T04:10:07.502-0700
^date^ ^ ^time^ ^offset
separator

Parse your date with time-of-day and offset-from-UTC as an java.time.OffsetDateTime object.

OffsetDateTime
.parse(
"2021-08-03T04:10:07.502-0700" ,
new DateTimeFormatterBuilder()
.parseLenient()
.append( DateTimeFormatter.ISO_LOCAL_DATE_TIME )
.appendPattern( "xx" )
.toFormatter()
)
.toString()

2021-08-03T04:10:07.502-07:00

Q1: And for this date (with hyphen): "2021-08-03T04:10:07.502-0700", the format is: ??

That string is in standard ISO 8601 format.

However, that string omits the optional COLON character between the hours and minutes of the offset-from-UTC. I would suggest always including that COLON for maximum compatibility in machines. And the COLON makes it more readable too for humans. So use this:

2021-08-03T04:10:07.502-07:00

Q2: Is the hyphen part the timezone GMT?

The HYPHEN-MINUS character in front of 0700 means the offset of seven hours is behind the temporal prime meridian of UTC.

-07:00 means seven hours behind UTC, as seen in the Americas.

  • +07:00 means seven hours ahead of UTC, as seen in Asia such as Thailand, Vietnam, Indonesia.

UTC is the new GMT, practically speaking, with regard to common business-oriented situations. If you are doing rocket science or GPS/Galileo satellite calculations, you should research the difference. If you are programming for purchase orders and invoices, don't worry about it.

Regarding your phrase, “the timezone GMT”… that is a contradiction. UTC/GMT is not a time zone. It is the baseline against which offsets are defined: a certain number of hours-minutes-seconds. What longitude is to the prime meridian, offsets are to UTC. Time zones are much more. Time zones are a named history of the past, present, and future changes to the offset used by the people of a particular region as decided by politicians.

Q3: If the date is in with the hyphen form after microseconds, how can one add X number of digits to address it?

Actually, the .502 is milliseconds, not microseconds.

And no, the date is up front, the 2021-08-03 part, August 3rd, 2021.

The T separates the date portion from the time portion. The third portion is the offset of -07:00.

Code

You said:

DateFormat dateFormat = new SimpleDateFormat(dateFormatWithHyphen);
dateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));

You are using terrible date-time classes that were years ago supplanted by the modern java.time classes defined in java.time. Never use Date, Calendar, SimpleDateFormat, and such.

Use OffsetDateTime to represent a date with time-of-day as seen with a particular offset-from-UTC.

If your input included the optional COLON, we could simply do this:

String input = "2021-08-03T04:10:07.502-07:00" ;
OffsetDateTime odt = OffsetDateTime.parse( input ) ;

Without the COLON, we must specify a formatting pattern. We can build up a DateTimeFormatter object by using a DateTimeFormatterBuilder.

DateTimeFormatter f = 
new DateTimeFormatterBuilder()
.parseLenient()
.append( DateTimeFormatter.ISO_LOCAL_DATE_TIME )
.appendPattern( "xx" )
.toFormatter()
;

Use that formatter.

OffsetDateTime odt = OffsetDateTime.parse( input , f ) ;

odt.toString(): 2021-08-03T04:10:07.502-07:00

Well, that code works. But the ideal solution would be convincing the publisher of your data to use the full ISO 8601 format including the COLON in every offset.

What is the correct date format for this date-as-a-string?

You need "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'" as date format

let dateFormatter = DateFormatter()
dateFormatter.locale = Locale(identifier: "en_US_POSIX")
dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"


guard let date = dateFormatter.date(from: self) else {
// fallback if date is not in correct format
return nil
}

What is this Date Time Format? 2019-01-17T10:49:55-05:00

It looks like ISO8601 format. The last section is how far from UTC/GMT it is. In this case -5 hours.

To add a bit more, this is THE standard way to transfer date and times between systems.

What does T mean in YYYY-mm-DDTHH:MM ?

The T isn't substituted for a value, it's a character used in the output to designate that the second part is a Time.

For example: 2021-04-20T13:03

The format is part of the ISO 8601 international standard.



Related Topics



Leave a reply



Submit