doutan2228 2013-04-17 13:41
浏览 62

将rss pubdate插入MySQL数据库

I try to insert a rss pubdate to my MySQL database. The format of the date is:

Tue, 16 apr 2013 17:04:08 UT

I try different function to format this pubdate, but I have problems with the timezone UT in the date. Functions I tried:

strftime("%a, %d %b %G %H %M %S", strtotime($pubdate));
date_create_from_format('D, d M Y G:i:s U', $pubdate);

Can anybody help me?

  • 写回答

2条回答 默认 最新

  • douchen2595 2013-04-17 19:12
    关注

    you are trying to insert in to a mySQL DateTime field right? so your goal is to get it to be in this format (YYYY-MM-DD HH:MM:SS)

    you can try this using strptime:

    $rssdate = "Tue, 16 apr 2013 17:04:08 UT";
    $parsed = strptime($rssdate,'%a, %d %b %Y %H:%M:%S %Z'); 
    $sqldate = date("Y-m-d H:i:s", mktime($parsed['tm_hour'], $parsed['tm_min'], $parsed['tm_sec'], $parsed['tm_mon']+1, $parsed['tm_mday'], 1900+$parsed['tm_year']));
    

    after that you should have gotten $sqldate with a value of

    2013-04-16 17:04:08
    

    take note that the UT will be discarded because of the DateTime field not being able to handle it. If you really need it, then just change your row into a String type if you can.

    Another thing, i tried using the date_create_from_format too but it seems that it cant recognize the month of April as 'apr' since in the format it needs to be capitalized like 'Apr'.

    评论

报告相同问题?

悬赏问题

  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大