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 |
$d = new DateTime( ‘@2444486400‘ ); |
2 |
$d ->setTimezone( new DateTimeZone( ‘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 |
$d = new DateTime( ‘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?
4 |
* Gets a prefixed unique identifier based on the current time in microseconds. |
6 |
function build_order_no() |
8 |
return date ( ‘Ymd‘ ). substr (implode(NULL, array_map ( ‘ord‘ , str_split ( substr (uniqid(), 7, 13), 1))), 0, 8); |
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