相关文章推荐
销魂的香菜  ·  java json 添加 java ...·  1 年前    · 
爱旅游的绿豆  ·  Flutter小技巧 - 掘金·  1 年前    · 
温柔的野马  ·  spring - Unable to ...·  1 年前    · 

I am trying to insert date and time into mysql datetime field from a string having following dd/mm/yyyy hh:mm:ss AM/PM format:

20/10/2014 05:39 PM

20/10/2014 05:39 AM

I know MYSQL timestamp format is yyyy-mm-dd hh:mm:ss or 0000-00-00:00:00:00

So if I do:

$s = substr("20/10/2014 05:39 PM", 0, 10);

$h = date("G:i", strtotime($s));

list($day, $month, $year, $hour, $minute) = split('[/ :]', "20/10/2014 05:39 PM");

echo $d1me = $year . '-' . $month. '-' . $day . ' ' . $h;

I get 2014-10-20 19:00

So I guess there is a problem with date_default_timezone_set() function, How to solve this and get expected result?

20/10/2014 05:39 PM -> 2014-10-20 17:39:00

20/10/2014 05:39 AM -> 2014-10-20 05:39:00

How to do it?

I am trying to insert date and time into mysql datetime field from a string having following dd/mm/yyyy hh:mm:ss AM/PM format:20/10/2014 05:39 PM20/10/2014 05:39 AMI know MYSQL timestamp format is yyy...
写过PHP+ MySQL 的程序员都知道有 时间 差,UNIX 时间戳 格式 日期 是我们常打交道的两个 时间 表示形式,Unix 时间戳 存储、处理方便,但是不直观, 格式 日期 直观,但是处理起来不如Unix 时间戳 那么自如,所以有的时候需要互相 转换 ,下面给出互相 转换 的几种 转换 方式。 一、在 MySQL 中完成   这种方式在 MySQL 查询语句中 转换 ,优点是不占用PHP解析器的解析 时间 ,速度快,缺点是只能用在数据库查询中,有局限性。 1. UNIX 时间戳 转换 日期 用函数: FROM_UNIXTIME() 一般形式:select FROM_UNIXTIME(1156219870); 2. 日期 转换 为UNIX 时间戳 用函数:
SELECT DATE_FORMAT(NOW(), '%Y%m') SELECT IFNULL(submit_month,"2021汇总"),COUNT( ymd ),ROUND(COUNT( ymd )/max( ymd ),3) SELECT CONCAT( SUBSTRING_INDEX(SUBSTRING_INDEX(submit_time,'-',2),'-',1), SUBSTRING_INDEX(SUBSTRING_INDEX(submit_tim 第二种:用date time()类输出当前 日期 时间 。它还将使用默认时区。 $datetime = new DateTime(); $datetime->format('Y-m-d H:i:s'); $danhao = date(' Ymd ').substr(implode(NULL, array_map('ord', str_split(substr(uniqid(), 7, 13), 1))), 0, 8); //生成 24 位唯一订单号码, 格式 :YYYY-MMDD-HHII-SS-NNNN,NNNN-CC,其中:YY select FROM_UNIXTIME(createdTime/1000, '%Y-%m-%d') as weekDay, COUNT(case WHEN `status`=0 then `status` END) as status0Count, COUNT(case WHEN `status`=1...
在 INSERT 或 UPDATE 查询中,TIMESTAMP 自动把自身设置为当前的 日期 时间 。 TIMESTAMP 也接受不同的 格式 ,比如 YYYYMMDDHHMMSS、YYMMDDHHMMSS、YYYYMMDD 或 YYMMDD。 format 可以使用的 格式 有: 格式 描述 %a缩写星期名 %b缩写月名 %c月,数值 %D带有英文前缀的月中的天 %d月的天,数值(00-31) %e月的天,数值(0-31) %H 小时 (00-23) %h 小时 (01-12) %I 小时 (0
在Hive和SparkSQL中,可以使用from_unixtime()函数将Unix 时间戳 转换 时间戳 。该函数的语法如下: from_unixtime(unix_timestamp[, format]) 其中,unix_timestamp是Unix 时间戳 ,format是可选参数,用于指定输出的 时间 格式 。如果不指定format,则默认输出为yyyy-MM-dd HH:mm:ss 格式 时间戳 。 例如,将Unix 时间戳 转换 时间戳 的示例代码如下: SELECT from_unixtime(1617888000); 输出结果为: 2021-04-08 00:00:00 这里的1617888000是Unix 时间戳 ,表示2021年4月8日的零点整。