Two PHP aspects of things, more than 2038 of the time and the unique order number algorithm

Source: Internet
Author: User
Tags ord

October 01, 2014 PHP development 1 reviews read 264 times Datetime::format is designed to be unaffected by external settings (object oriented)
So no matter how you change the environment parameter date_default_timezone, it will not affect the output result
To change the Datetime::format time zone setting, you need to

Datetime::settimezone Pass in a time zone object Datetimezone

1 $dnewDateTime(‘@2444486400‘);
2 $d->setTimezone(newDateTimeZone(‘PRC‘));
3 echo$d->format(‘Y-m-d H:i:s‘);    //2047-06-19 00:00:00

Converts a standard time greater than 2038 into a timestamp

1 $dnewDateTime(‘2047-06-19 00:00:00‘);
2 echo$d->format(‘U‘);    //2444486400

Excerpt from: http://levi.cg.am/archives/2868

PHP generates a unique order number algorithm:

Use Uniqid to get a unique, non-repeating string based on the current number of microseconds (but his first 7 bits seem to change for a long time, so don't worry about deleting it), take 8th to 13th place. But this string contains the English alphabet, what should I do?
Use Ord to get his ASCII code, so there's the next step: use Str_split to divide the string into arrays and use Array_map to manipulate it (faster).
Then returned is an array, KO, in a string with implode, but the character length is variable, take the previous fixed several, and then precede the current year and date, this method generates the order number, the world will not have much repetition.

View Source print?
1 /**
2  *
3  * uniqid - 官方是这样说的:
4  * Gets a prefixed unique identifier based on the current time in microseconds.
5  */
6 functionbuild_order_no()
7 {
8     returndate(‘Ymd‘).substr(implode(NULL, array_map(‘ord‘,str_split(substr(uniqid(), 7, 13), 1))), 0, 8);
9 }

Part of the algorithm excerpt from: http://levi.cg.am/archives/3373

Two PHP aspects of things, more than 2038 of the time and the unique order number algorithm

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.