从MySQL的时间戳中获取日名



如何从MySQL中的时间戳数据类型获得日期名称?

2013-01-01 15:00:28应该返回Tuesday

SELECT DAYNAME('2013-01-01 10:10:10');

短日名示例。这将返回' true ':

SELECT DATE_FORMAT('2013-01-01 15:00:28','%a') as dayname;

长日名称示例。这将返回'Tuesday':

SELECT DAYNAME('2013-01-01 15:00:28') as dayname;

或者用您使用的任何语言格式化它。

让说…PHP:

<?php
$date = '2013-01-01 15:00:28';
$datetime = new DateTime($date);
$formated_date = $datetime->format('l'); // Tuesday

JavaScript:

var original_date = '2013-01-01 15:00:28';
var day_names = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"]
var date_object = new Date(x);
var formated_date = day_names[date_object.getDay()];
// alert or print formated_date

相关内容

  • 没有找到相关文章

最新更新