How do I get the format of “yyyy-MM-ddTHH:mm:ss.ff

2019-08-04 16:44发布

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

4条回答
Fickle 薄情
2楼-- · 2019-08-04 17:19

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.

查看更多
闹够了就滚
3楼-- · 2019-08-04 17:22

.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

查看更多
ら.Afraid
4楼-- · 2019-08-04 17:26

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.

查看更多
啃猪蹄的小仙女
5楼-- · 2019-08-04 17:27

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.

查看更多
登录 后发表回答