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

Php从字符串获取月份编号与日期[重复]

This question already has an answer here:

  • Get month of a given date 7 answers

i have a string in this format '2015-4-28' How i get month number for this string ( the value in this example is 4)?

Thanks

</div>

Another option would be to do this:

date('m', strtotime($date));

Change the m to an n to get the month without the leading 0.

With this:

<?php
$a = "2015-4-28";
$parts= explode("-", $a);
echo $parts[0]; // 2015
echo $parts[1]; // 4
echo $parts[2]; // 28
?>

近期文章

  • MYSQL:从具有外键的表中删除
  • 为什么SimpleXML无法识别字段
  • PHP - Jquery联系表单发送空白电子邮件
  • CodeIgniter .htaccess用于我的文件结构
  • 如何在imagick上禁用字体平滑?
  • 如何使用for循环比较两个数组?
  • mySQL无法插入其中一个表
  • WPF app + PHP,最快的沟通方式
  • 使用Doctrine按子类字段排序
  • 在foreach里面插入mysql是不行的?
  • 来自3个表的SUM表的SQL报告
  • 可以在查询字符串值中使用连字符吗?
  • 文件存在,但我无法使用PHP打开它
  • 使用php和mysql创建动态菜单
  • 两个从正常表格和模态表格提交
  • 无法显示有关用户的详细信息(codeigniter)
  • 在nginx转发后保持域名相同?
  • DateTime对象生成不正确的结果
  • 自定义帖子类型/分类法用户关联
  • Knockout Js功能没有出现在页面上

Copyright ©2022 我爱占星 All Rights Reserved.

浙ICP备2022030071号-1

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

友情链接:代码精华