将日期转换为日期名称,例如周一,周二,周三 [英] Convert date to day name e.g. Mon, Tue, Wed

查看:147
本文介绍了将日期转换为日期名称,例如周一,周二,周三的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个变量,它以以下格式输出日期:

I have a variable that outputs the date in the following format:

201308131830

哪个是2013年-8月-13-18:30

Which is 2013 - Aug - 13 - 18:30

我正在使用它来检索日期名称,但它得到的日期错误:

I am using this to retrieve the day name but it is getting the wrong days:

$dayname = date('D', strtotime($longdate));

知道我在做什么错吗?

推荐答案

当您以非标准格式存储日期和时间时,会发生这种情况.与他们合作变得成问题.

This is what happens when you store your dates and times in a non-standard format. Working with them become problematic.

$datetime = DateTime::createFromFormat('YmdHi', '201308131830');
echo $datetime->format('D');

查看实际效果

这篇关于将日期转换为日期名称,例如周一,周二,周三的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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