日期格式化在php [英] date formatting in php

查看:94
本文介绍了日期格式化在php的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个如下所述的字符串:

I am having a string as mentioned below:

$ts  = "3/11/09 11:18:59 AM"; which I have got using date() function

现在我需要将其转换为如下所示的可读格式

Now i need to convert this to a readable format like below

11-Mar-2009

我曾经尝试过使用date()的所有内容。

I have ave tried everything using date()

有人可以帮助我吗?

推荐答案

您需要将其转换为可用于进一步格式化的内容。 strtotime()是一个很好的开始,它产生一个unix时间戳。您可以使用 strftime()格式化该格式。

You need to convert it to something you can use for further formatting. strtotime() is a good start, which yields a unix timestamp. You can format that one using strftime() then.

strftime("%d-%b-%G", strtotime($ts));

这篇关于日期格式化在php的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆