我爱占星网 我爱占星网
首页
编程
java
php
前端
首页 编程 java php 前端

忽略createFromFormat中的纳秒

I'm trying to create a DateTime from the following string:

2012-02-16 00:45:54.441899

I tried with this format, without success:

Y-m-d H:i:s.*

What can I do? I don't care about the part after the dot.

you forgot the microsecond part of the format:

$s = '2012-02-16 00:45:54.441899';
$d = DateTime::createFromFormat('Y-m-d H:i:s.u', $s);//format looks like your string
echo $d->format('Ymd');//output format can be whatever you like

近期文章

  • 排序mysql结果
  • 访问管理页面
  • 是否可以在单引号字符串中插入变量?
  • filesize()[function.filesize]:LinqBridge.dll中的stat失败
  • 初始视图后显示/隐藏
  • 如何INSERT天来保持MYSQL日历表最新?
  • 具有共同祖先冗余的PHP抽象对象设计
  • 将youtube视频标题拉入页面
  • 通过ajax分割输出值,
  • mysql PHP join - 语法问题
  • 随机定位图像,没有重叠
  • Symfony Admin生成器 - 显示Doctrine Collection
  • php数组索引
  • 将时间戳月份/年列为PHP中的博客存档
  • 使用PHP搜索MySQL时如何显示错误
  • 如何使用一个参数从PHP中的url中识别variables_x列表?
  • Codeigniter:来自DB的简单数据回显
  • 不会出现嵌入在iframe中的产品的亚马逊页面
  • 功能设置$ _SESSION中的所有$ _COOKIE变量都不起作用
  • 无法打开流:HTTP请求失败

Copyright ©2022 我爱占星 All Rights Reserved.

浙ICP备2022030071号-1

部分图文来自网络,如有侵犯您的版权,请告诉我们删除

友情链接:代码精华