
- PHP 7 Tutorial
- PHP 7 - Home
- PHP 7 - Introduction
- PHP 7 - Performance
- PHP 7 - Environment Setup
- PHP 7 - Scalar Type Declarations
- PHP 7 - Return Type Declarations
- PHP 7 - Null Coalescing Operator
- PHP 7 - Spaceship Operator
- PHP 7 - Constant Arrays
- PHP 7 - Anonymous Classes
- PHP 7 - Closure::call()
- PHP 7 - Filtered unserialize()
- PHP 7 - IntlChar
- PHP 7 - CSPRNG
- PHP 7 - Expectations
- PHP 7 - use Statement
- PHP 7 - Error Handling
- PHP 7 - Integer Division
- PHP 7 - Session Options
- PHP 7 - Deprecated Features
- PHP 7 - Removed Extensions & SAPIs
- PHP 7 Useful Resources
- PHP 7 - Quick Guide
- PHP 7 - Useful Resources
- PHP 7 - Discussion
Get unix timestamp from string without setting default timezone in PHP
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
- Related Articles
- How to get the Unix timestamp in C#
- How to convert from Unix timestamp to MySQL timestamp value?
- Convert dd/mm/yyyy string to Unix timestamp in MySQL?
- Convert MySQL timestamp to UNIX Timestamp?
- Convert timestamp coming from SQL database to String PHP?
- How to convert unix timestamp string to readable date in Python?
- Convert MM/DD/YY to Unix timestamp in MySQL?
- Convert UNIX timestamp into human readable format in MySQL?
- How to convert Python date to Unix timestamp?
- Convert MySQL Unix-Timestamp format to date format?
- How to convert MySQL datetime to Unix timestamp?
- MySQL - Convert YYYY-MM-DD to UNIX timestamp
- How to get parameters from a URL string in PHP?
- How to Detect User Timezone in PHP?
- How to convert a Unix timestamp to time in JavaScript?

Advertisements