dshmkgq558192365 2012-07-18 20:03
浏览 31
已采纳

这是什么日期格式? (PHP Codeigniter文件助手)

I'm trying to work out what format this date is in!

  'date' => int 1342640973

Date today is 18.07.2012

I got it from the get_file_info function in the CI File Helper.

  • 写回答

3条回答 默认 最新

  • dongpo8250 2012-07-18 20:12
    关注

    It's a unix timestamp!

    The value you have represent a date/time in seconds since the first of January 1970 (in UTC), it's often referred to as a "unix timestamp" because of it's origin.

    Handling this time representation is easily done in PHP, there are native functions made to convert back and to the format.


    time () will return the current time in the format specified (unix timestamp), to convert this into a readable string you can use date with the appropriate format-string, as in the below example:

    $unix_timestamp = 1342640973;
    $now_utimestamp = time (); 
    
    print_r (
      array (
        date ("Y-m-d G:i:s", $unix_timestamp),
        date ("Y-m-d G:i:s", $now_utimestamp)
      )
    );
    

    output on my system:

    Array
    (
        [0] => 2012-07-18 21:49:33
        [1] => 2012-07-18 22:18:43
    )
    

    Unless you have told PHP which timezone it's currently in (using php.ini or equivalent) you'll need to specify this using the function date_default_timezone_set(), passing it the value of date_default_timezone_get() will try to set it according to your system preferences.

    If it's unable to find a correct match UTC will be used per default.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥30 BC260Y用MQTT向阿里云发布主题消息一直错误
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)