
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Get Unix Timestamp from String in PHP Without Setting Default Timezone
String has a time zone, and there is usually no need to set a default time zone. But when it needs to be printed, the default time zone can be set explicitly. Below is the code to do the same −
Default timezone
Example
echo date_default_timezone_get();
Output
This will produce the following output −
UTC
When timezone is specified
Example
echo date("Y-m-d H:i:s",strtotime("1/1/2020 00:00:00 America/Los_Angeles"));
Output
This will produce the following output −
2020-01-01 08:00:00
Another way of specifying timezone
Example
echo date("Y-m-d H:i:s",strtotime("1/1/2020 00:00:00"));
Output
This will produce the following output −
2020-01-01 00:00:00
Advertisements