我有一个包含日期列的mysql数据库,使用datetime数据类型。
但现在我想将数据类型从datetime更改为长整数。
我想知道如何将日期转换为任何整数值。
假设我有一个日期
例如2012-03-27 18:47:00
那么我想知道是否可能将其转换为任何整数,比如131221154
使用PHP的strtotime
函数。
该函数期望传入一个包含英文日期格式的字符串,并尝试将该格式解析为Unix时间戳(自1970年1月1日00:00:00 UTC以来的秒数),相对于当前时间戳或未提供now参数时的当前时间。
echo strtotime('2012-03-27 18:47:00'); //--> which results to 1332866820
要将其转换回来,只需使用PHP的date
函数:
$long = strtotime('2012-03-27 18:47:00'); //--> which results to 1332866820
echo date('Y-m-d H:i:s', $long);
strtotime("1900-06-12")
是什么意思? - Máxima Alekz检查这个
<?php
$timestamp = strtotime('1st January 2004'); //1072915200
// this prints the year in a two digit format
// however, as this would start with a "0", it
// only prints "4"
echo idate('y', $timestamp);
?>