I use the date() function to get day, month and year.
$year = date(y);
$month = date(m);
$day = date(d);
But my hosting is in another place where I am, so I need to add 11 hours. could you tell me how can I do that? thanks
Use the toLocaleString() method to initialize a date with time zone, e.g. date. toLocaleString('en-US', { timeZone: 'America/Los_Angeles'}) . The method can be passed the locale and the time zone as parameters and returns a string that represents the date according to the provided values.
For specific time zone select you can use date_default_timezone_set before using date() or time() function. And to specify the timezone : $now = new DateTime(null, new DateTimeZone('Asia/Dhaka')); $now->setTimezone(new DateTimeZone('Asia/Dhaka')); // Another way echo $now->getTimezone();
To convert a date to another time zone: Use the toLocaleString() method to get a string that represents the date according to the provided time zone. Pass the result to the Date() constructor. The returned Date object will have its date and time set according to the provided time zone.
Either do
date('Y-m-d', strtotime('+11 hours'));
to add 11 hours or create a DateTime object and change it's timezone where needed
$datetime = new DateTime; // current time = server time
$otherTZ = new DateTimeZone('America/Los_Angeles');
$datetime->setTimezone($otherTZ); // calculates with new TZ now
or simply set the appropriate timezone with
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With