I have a MySQL database that records the time when a given event occurs. There's a web app that show's these times when you load the page BUT its in +0 TimeZone. I want this to show what ever timezone that the user is in.
echo(date('l F jS Y h:i:s A', ($row["date"]/1000)- 3600*6));
The above code shows that if I want the timezone to be central I have to *6. But this would just be the new timezone then and doesn't change based on users location.
Also a added bonus would to be able to display at the top of the page somewhere the users IP address, City and State.
EDIT:
Trying to get the UTC timezone # into a $variable.
Example being Central Time would = -6.
echo(date('l F jS Y h:i:s A', ($row["date"]/1000)-(3600*(-1*$variable))));
If you want to have the correct time zone set on page load you are going to need to store the users time zone as a preference in your application. Unfortunately PHP (or any backend language) for that matter does not have access to such browser information (unless you additionally pass it to the server-side script).
The other option is to pass the UTC date or server timezone date, get the user's time zone and convert your date to their local time using Javascript.
You can get the UTC time zone offset with
var d = new Date()
d.getTimezoneOffset();
Related
I have an Android App linked to an SQL database,
Now when the user posts a comment from the app, I want to get his real time and date (based on user's timezone).
I've already tried functions like date() and time() but these functions get the remote server time not the user's time.
Is there an api or similar, that I can use to do that - such as get time from IP address ?
In phpinfo, default.timezone & default.datetime as America/New_york.
In joomla configuration file offset as "America/Newyork". Offset user as "UTC". In backend user setting as "Newyork."
Actually the problem as When i create a article, the time save as as UTC format in database, But when we view the created date in the article, it shows 5 hours ahead to the created time. Whenever i save the article it increase 5 hours from the current date.
Please advice.. Thank you.
Add this line as the first line in your code,
date_default_timezone_set('Asia/Kolkata');
Change the timezone ('Asia/Kolkata') to your timezone.
You can check your timezone name Here.
If it is specific about Joomla, then
using JHtml::('date' , ....) for output
https://compojoom.com/blog/entry/how-to-use-jdate
Also, When you call JFactory::getDate() it will construct a JDate object, which already takes the timezone into account.
More info:
http://docs.joomla.org/How_to_use_JDate
http://api.joomla.org/cms-3/classes/JDate.html
http://api.joomla.org/cms-3/classes/JFactory.html#method_getDate
Finally, I found the issue in the server timezone. I have changed the server timezone to GMT/UTC. it was working fine. Thanks for all your contribution
I am working on a Symfony2 based website where client can request users to post at a particular time of the day for exemple from 9pm to 10pm.
Users are coming from all over the world and if a client request a post at 9pm, it s not based on his local time but on the user that will post for him.
Should i request my user what is his timezone and store it and then use it to convert the php DateTime of his post to his time zone and then check if he posted it at 9pm ? Could you show me a little code exemple for that ?
Also, what is the good way to ask a user his timezone ?
Edit : I want to ask the user his timezone and not get it programmatically because its actually his audiance timezone ( people who see his posts ) and not his personnal timezone.
best way is to use js timezone detection with library jsTimezoneDetect
next send via ajax request timezone to save in session
next use timezone in session to set timezone to date, you probably want to make twig extension for that so you can use it easily in twig.
1. all your dates must be in same timezone, for example UTC
you can set it in AppKernel.php
date_default_timezone_set('UTC');
to display date use something like this
$date->setTimezone(new \DateTimeZone($timezone));
where date is \DateTime object
if you want to ask user anyways you can create form with:
you create a form, use http://symfony.com/doc/current/reference/forms/types/timezone.html
field
and send that timezone to controller (AJAX or standard), set session with timezone, and for the rest handle it like like I described above by displaying date via your custom twig extension etc.
I have implemented my own script for auctions. But my problem is how to handle time.
Right now all auctions are based on UTC time, so whatever user's timezone is when he/she comes to site auction will start and end at the same time(UTC). I used date_default_timezone_set('UTC') to set default timezone throughout whole site.
But I guess that might be little bit confusing for users. Did anyone have similar problem and what could be the best solution for it.
I created a family website (family around the world).
All dates were stored with timestamp (which is UTC-timezone independent).
When a member created an account, he/she had to enter the country he/she was living it (as the PHP timezone guess is not reliable).
From that, I stored the name of the timezone of his /her country (https://php.net/manual/en/timezones.php).
When the member logs in, I PHP-set the timezone to his/her country to display dates with his/her timezone.
I am working on rss parser project, I need to fetch URL from us based server and store the data in to database while storing/viewing I need to keep the post time.
I am using simplepie for rss aggregation, I face the following problem while handling rss
while I am checking rss url in firefox 3.0.19/system timezone set to Chennai/Kolkatta/Mumbai(UTC+5:30)now firefox displays post time for the post is 10:51 am
at the same time if i check the same url in another system which has firefox 3.6.1/system timezone set to Chennai/Kolkatta/Mumbai(UTC+5:30) now firefox displays post time for the post is 11:34 am
how do I know which time is correct?
and how do I get timezone for the RSS Server for php
RSS Feeds stored in one server and I installed PHP application in another server both of them located in us.
Which timezone should I use?
i set following time zone in my code
<?php
date_default_timezone_set('US/Central');
?>
but post time is wrong when display
i solved the problem my self using below method
get list of all timezones take first post's post date and set the first timezone format the date and set the second timezone format the date and so on.. finally i compared formatted date with postdate then i got the timezone of the server