Editing
PHP microtime to MySQL timestamp
Jump to navigation
Jump to search
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
{{exclaim}} Warning: It will lose the accuracy after conversion. Microtime ex: 1426299057.8639 will lost the numeric after point (.8639) after saved to {{kbd | key = TIMESTAMP}} type ex: 2015-03-14 10:10:57 (equals to 1426299057) 1. Check the MySQL server's current time zone: {{kbd | key =<nowiki>show variables like '%time_zone%';</nowiki>}}<ref>[http://dev.mysql.com/doc/refman/5.7/en/time-zone-support.html MySQL :: MySQL 5.7 Reference Manual :: 10.6 MySQL Server Time Zone Support]</ref>. It's also the timezone which the data with {{kbd | key = TIMESTAMP}} type stored. example output: <pre> Variable_name Value system_time_zone CST time_zone SYSTEM ## my SYSTEM timezone is Asia/Taipei </pre> 2. PHP codes ([http://ideone.com/iRy0fI online demo]) <pre> //set the current timezone date_default_timezone_set("Asia/Taipei"); $microtime = microtime(true); //1426299057.8639 list($second, $numeric_after_point) = explode(".", $microtime); //$second: 1426299057 //$numeric_after_point: 8639 $timestamp = date('Y-m-d H:i:s', $second); //$timestamp: 2015-03-13 10:10:57 </pre> == References == <references/> [[Category:PHP]] [[Category:Programming]] [[Category:Web_Dev]] [[Category:Time river]]
Summary:
Please note that all contributions to LemonWiki共筆 are considered to be released under the Creative Commons Attribution-NonCommercial-ShareAlike (see
LemonWiki:Copyrights
for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource.
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Templates used on this page:
Template:Exclaim
(
edit
)
Template:Kbd
(
edit
)
Navigation menu
Personal tools
Not logged in
Talk
Contributions
Log in
Namespaces
Page
Discussion
English
Views
Read
Edit
View history
More
Search
Navigation
Main page
Current events
Recent changes
Random page
Help
Categories
Tools
What links here
Related changes
Special pages
Page information