How PHP converts dates to JDE's Julian calendar format

Source: Internet
Author: User
This article mainly introduces the conversion of the date of PHP to JDE of the Julian calendar format method, has a certain reference value, now share to everyone, the need for friends can refer to

JDE's Julian calendar format rules are as follows:

The Julian calendar is a 6-digit number; (Example: January 1, 2018 = "118001)

The first digit represents the Century (example: 1 represents 21st century; 0 represents 20th century);

The 23rd digit represents the Year (example: 2018 is 18);

The number of days after the first 3 digits of the 1 year;

Here's how:

/** * Date converted to Jde Calendar "Support time Conversion Range: 1970-2,999" * "Six-bit: first identity century Example: 0 for 20th century, 1 for 21st century, second to third for year, and the last three for the first day of the Year" * Example: 2018-01-01  = "118001 * @param $date * @return string */function getjdedate ($date) {    #转换为时间戳    $unix _time = Strtotime ($date); 
  
    #获取时间信息    $ary _date = getdate ($unix _time);    #获取年    $str _year = $ary _date[' year ');    #获取世纪标识 "20th century = 0; 21st century = 1; 22nd century = 2 "    #如果年/100 Surplus    if ($str _year%100) {            $century = ceil ($str _year/100)%10; #向上取整    } else {            $century = Floor ($str _year/100)%10; #向下取整        }    #获取年后两位    $year = substr ($str _year,2);    #获取一年中的第几天    $year _day = $ary _date[' yday ') + 1;    #如果不足三位数补足三位数    $year _day = Str_pad ($year _day,3,0,str_pad_left);    #儒日历    return $century. $year. $year _day;}
  

Test Case:

<?php/** * Date converted to Jde Calendar "Support time Conversion Range: 1970-2,999" * "Six-bit: first identity century Example: 0 for 20th century, 1 for 21st century, second to third for year, and the last three for the first day of the Year" * Example: 2018-01-  118001 * @param $date * @return string */function getjdedate ($date) {    #转换为时间戳    $unix _time = Strtotime ($da TE);    #获取时间信息    $ary _date = getdate ($unix _time);    #获取年    $str _year = $ary _date[' year ');    #获取世纪标识 "20th century = 0; 21st century = 1; 22nd century = 2 "    #如果年/100 Surplus    if ($str _year%100) {        $century = ceil ($str _year/100)%10; #向上取整    } else {        $century = Floor ($str _year/100)%10; #向下取整    }    #获取年后两位    $year = substr ($str _year,2);    #获取一年中的第几天    $year _day = $ary _date[' yday ') + 1;    #如果不足三位数补足三位数    $year _day = Str_pad ($year _day,3,0,str_pad_left);    #儒日历    return $century. $year. $year _day;} echo getjdedate (' 2018-01-01 00:00:00 ');

Output:

118001

The above is the whole content of this article, I hope that everyone's learning has helped, more relevant content please pay attention to topic.alibabacloud.com!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.