2

I need to get a datetime format of yyyy-MM-ddTHH:mm:ss.fffZ to use in creating a hash to talk with a .NET server. How can I get that format in PHP? I don't know what "fffZ" even is to try to figure this out myself and can't find it online. Help is greatly appreciated.

Thanks, James

1

4 Answers 4

10

Using PHP you can get it in this way:

date('Y-m-dTH:i:s.uZ')  //for the current time

You can find each character at the documentation. Although I'm not sure if the Z means the same in both languages.

2
  • Thanks, this outputs 2013-03-22EDT12:56:35.000000-1440016.
    – James
    Mar 22, 2013 at 16:58
  • I think its date("Y-m-d\Th:i:s.v\Z") for current time, the flag v is output the 3 integer before Z May 8, 2022 at 16:34
4

.fffZ refer to milliseconds and the timezone.

.fff specifies 3 decimal places of milliseconds.

Z is the timezone (+0000 UTC e.t.c).

You may find this page useful: link

2
2

See Custom Date and Time Format Strings

fff The milliseconds in a date and time value.Specifier.

and

"z" Hours offset from UTC, with no leading zeros.

To get the corresponding format in PHP, see date.

2

According to MSDN, fff is milliseconds:

http://msdn.microsoft.com/en-us/library/8kb3ddd4.aspx

Z is going to be timezone. You can handle getting that in PHP by http://php.net/manual/en/datetime.gettimezone.php.

The rest should be pretty straight forward.

Edit: Actually, forgot that Z in .NET is going to be offset from UTC. Seems like you can get that from something similar to UTC Offset in PHP.

Not the answer you're looking for? Browse other questions tagged or ask your own question.