如何将COledatetime转换为unix时间/php时间?
如何将 COleDateTime::GetCurrentTime() 转换为 unix 时间戳,或者更具体地说,我想转换该值,以便可以在 PHP 中通过 date() 函数使用它?
How can I convert a COleDateTime::GetCurrentTime() to a unix time stamp or more specifically I want to convert the value so I can use it in PHP with the date() function?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
下面是一个简单的 Python 函数,用于将 COleDateTime 值转换为 Python 日期时间对象。如果没有别的事,您可以使用它将 COleDateTime 转换为 POSIX 时间格式以供 PHP 摄取。假设您的 COleDateTime 值(原始情况下为 40224.00000000)被传递到浮点值“dateval”。
我只是在 MSDN 文档中指定的开始日期和时间 (1899-12-30 @ 0:00) 创建一个基本日期时间,并添加天数和部分天数的时间增量。它不处理时区,但 COleDateTime 也不处理(据我所知)。如果没有其他的,它对您的测试用例有效,返回日期 2010-02-15 和时间 0:00 的 Python 日期时间对象。
Here's a simple Python function to convert COleDateTime values to Python datetime objects. If nothing else, you can use this to convert the COleDateTime to a POSIX time format for ingestion by PHP. Assume your COleDateTime value (40224.00000000 in the original case) is passed into a floating point value "dateval".
I just create a base datetime at the start date and time specified in the MSDN documentation (1899-12-30 @ 0:00) and add timedeltas for the number of days and partial days. It doesn't deal with timezones, but neither does COleDateTime (so far as I know). If nothing else it works for your test case, returning a Python datetime object for the date 2010-02-15 and time 0:00.
这听起来像 DATE 类型:
测试代码:
打印
40224.000000
。我不认为有一个内置函数可以将其转换回任何“本机”php 日期/时间值(尽管可能是错误的)。
编辑:转换函数的(可能是幼稚的)起点...
正常,但
似乎工作
虽然这 9 个示例
我不确定 intval()/round() 以及 php 代码是否必须遵循其他约定。如果您要使用此功能,请对其进行测试,然后使用更多样本再次进行测试。
请记住,这仅限于小于 COleDateTime 范围的 unix 时间戳范围。
That sounds like the DATE type:
test code:
prints
40224.000000
.I don't think there is a built-in function to convert this back to any "native" php date/time value (could be wrong though).
edit: A (probably naive) starting point for a conversion function...
some sample data create by
lead to
which prints
Though these 9 samples seem to work ok I'm not sure about intval()/round() and whether there are other conventions the php code must follow. If you're going to use this function, test it And then test it again with a lot more samples.
And keep in mind that this is limited to the unix timestamp range which is smaller than the range of COleDateTime.
COleDateTime::GetCurrentTime()
返回一个对象,据我在 MSDN 文档中所知,它不会输出字符串。如果您可以提供在 XML 中获取的字符串的示例,那么为您提供答案会容易得多。COleDateTime::GetCurrentTime()
returns an object, it doesn't output a string as far as I can tell in the MSDN Documentation. If you can provide an example of the string you are getting in the XML, it would be much easier to provide an answer for you.