如何从 MySQL 中的时间戳数据类型获取日期名称?
2013-01-01 15:00:28
应该返回Tuesday
SELECT DAYNAME('2013-01-01 10:10:10');
短日名称示例。这将返回“星期二”:
SELECT DATE_FORMAT('2013-01-01 15:00:28','%a') as dayname;
长天名称示例。这将返回“星期二”:
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