Flins
Flins

Reputation: 221

Get system time using PHP and dealing with offsets/timezones

How can I get the system time, like 10.23 PM, and how do I properly deal with time offsets and timezones?

Upvotes: 0

Views: 3153

Answers (4)

Partha Das
Partha Das

Reputation: 11

Find your php.ini file location and edit it like this:-

  1. Find date.timezone and set it to your local timezone name as used in php.
  2. Find date.default_latitude and set it to your server location's latitude.
  3. Find date.default_longitude and set it to your server location's longitude.

For longitude / latitude, google it with your city name.

IMPORTANT NOTE : After you edit this information, save the php.ini file and close it. Then RESTART your server. Without restarting, you might not be able to see the changes.

Upvotes: 1

muruga
muruga

Reputation: 2122

<?php
$time_now=mktime(date('h'),date('i'),date('s'));
print date('h.i A',$time_now);
?>

Upvotes: 0

Matthew
Matthew

Reputation: 48284

http://www.php.net/manual/en/function.date.php

echo date("g:i A")

Upvotes: -1

Tatu Ulmanen
Tatu Ulmanen

Reputation: 124768

Like this:

echo date('g.i A');

Check the PHP date() reference. date() takes an optional second argument which you can use to set a custom timestamp. Without this argument, date() returns the current time.

Upvotes: 1

Related Questions