How do I get the format of “yyyy-MM-ddTHH:mm:ss.fffZ” in php? [closed]

Deadly 提交于 2019-12-11 08:33:22

问题


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:


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:


.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




回答3:


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.




回答4:


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.



来源:https://stackoverflow.com/questions/15574434/how-do-i-get-the-format-of-yyyy-mm-ddthhmmss-fffz-in-php

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!