php - 如何从 PHP 中的 DateTimeInterface 创建 DateTime?
问题描述
这是一个相当简单的问题,但我在互联网上找不到真正的答案。
所以假设,在 PHP 中,我有一个 a 的实例DateTimeInterface
,并且我需要 aDateTime
在同一时间。这样做的首选方法是什么?通过字符串进行转换似乎相当复杂,我不确定要使用哪种格式。也许通过时间戳?我不确定在涉及时区时这是否有效。
解决方案
在 PHP 8 中:createFromInterface:
$dateTime = DateTime::createFromInterface($dateTimeInterface);
推荐阅读
- c++ - C++ 中的空向量特性
- javascript - 如何处理长选择:下拉或选择选项?
- mysql - 应用程序从 Mongo 迁移到 MySql
- c++ - 尝试从 C++ 中的类返回 Bool 值
- javascript - 如何从包含数组对象的对象中获取值?
- windows - Windows Batch:使用本机命令根据关键字拆分文件
- typescript - NestJS 从守卫中抛出 http 异常(导出为库模块)
- c++ - C ++如何修复错误未定义的函数引用?
- c++ - 何时使用英特尔的指令集扩展技术
- amazon-web-services - 在 AppSync 订阅中添加 CORS 过滤器