Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What if the ECSHOP timestamp conversion difference is 8 hours?

2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Network Security >

Share

Shulou(Shulou.com)05/31 Report--

The purpose of this article is to share with you what to do about the ECSHOP timestamp conversion difference of 8 hours. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

If ecshop saves the date directly and then transfers the timestamp to the year, month and day through date (), there will be an error of 8 hours. There is a setting time in the background, and the normal secondary development time display will be processed, so there will be no problem.

Since I wrote the PHP code to call the date, the period of direct reading is 8 hours less, and the time recorded before 8 o'clock in the morning will all be attributed to the date of the previous day.

Solution:

Date ('Ymurm add_time'])

Replace it with

Local_date ('YmurmMurdhi, $row [' add_time'])

It can be the unified setting time format of ECSHOP:

Local_date ($GLOBALS ['_ CFG'] ['date_format'], $row [' add_time'])

The following online search materials, expand reading:

There are two types of PHP time, one is the timestamp type (1228348800), and the other is the normal date format (2008-12-4).

So there are two forms of saving to the database (really more than, my application is two), the type of timestamp I save as a string, this is more convenient.

The normal date type is saved as date.

These two should pay attention to, I usually use two, so, the table built a few days ago, the time type is saved as DATE, I have been using timestamps to save, the data has not been written into the table, debugged for a long time to know the error, is the type does not match, do not write into the library.

Like the above timestamp is more convenient, but, when displayed, it is not so good to show this 1228348800 string to the customer, GOD NOWS!

So use the conversion of these two, first talk about how to get the current timestamp, $date1=time (); so get the current timestamp, to switch back to 2008-12-4 this format, use date () this function, in PHP date () function is more commonly used, such as get the current date, you can use $date2=date ('YmurmMuidd'); about the meaning of the parameters inside, if you do not understand, check the php manual.

All right, let's get down to business. The code for converting 1228348800 to 2008-12-4 is as follows:

$date3=date ("1228348800"), "Y-m-d"

This is the OK. If you still want to get hours, minutes and seconds, you just need to change the 'YMMI'. However, you should note that the PHP time still seems to have an error of 8 hours. Add it to OK.

If the timestamp changes to the normal date, on the contrary, if you change the normal date format to a timestamp, please see the following code:

$year= ((int) substr ("2008-12-04", 0pr 4)); / / obtained the year

$month= ((int) substr ("2008-12-04", 5pr 2)); / / acquisition month

$day= ((int) substr ("2008-12-04", 8meme2)); / / get the number

Echo mktime (0pr 0pr 0rem monthje mnh mnthrem DayRen year)

In this way, you can turn the normal date into a timestamp, and it's the same here if it happens every minute and second.

Note: the time stamp above php5.1 will differ from the actual time by 8 hours. The solution is as follows.

1. The easiest way is not to use a version above php5.1-obviously this is not a desirable method!

2. Modify php.ini. Open php.ini to find date.timezone, remove the semicolon before = add Asia/Shanghai after it, and restart the apache server-the disadvantage is that if the program

Put it on someone else's server, and you can't modify the php.ini, so what can you do?

3. Add the initialization statement of time to the program, that is, "date_default_timezone_set (" Asia/Shanghai ");" this can be set by the programmer at will, my push

Recommend.

Time zone identifier, the values available on the mainland are: PRC,Asia/Chongqing, Asia/Shanghai, Asia/Urumqi (followed by China, Chongqing, Shanghai, Urumqi), Etc/GMT-8,Asia/Harbin

Available in Hong Kong and Taiwan: Asia/Macao, Asia/Hong_Kong, Asia/Taipei (Macau, Hong Kong, Taipei in turn)

And Singapore: Asia/Singapore

Australia: Australia/Sydney

Thank you for reading! This is the end of the article on "what to do with the difference of 8 hours in ECSHOP timestamp conversion". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Network Security

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report