Time zone handling in php - php

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

Related

How I Can Get The Real Time & Date Of User with php

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 ?

Article created date shows 5 hours ahead to the current time

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

Facebook PHP SDK searching for posts within time-frame

I am attempting to fetch all posts and respective comments of a user within a certain time frame and I am having trouble finding the fields for the FB SDK. I see the "until" option but I do not see a usage/explanation of it.
me/posts?fields=object_id,shares,source,story,to,link&limit=10
I want to add a field that only collects posts between two dates. I will then get rid of the limit field. Any suggestions/resources will be great!
Thanks!
The information can be found here: https://developers.facebook.com/docs/graph-api/using-graph-api
A time-paginated edge supports the following parameters:
Until : A Unix timestamp or strtotime data value that points to the end of the range of time-based data
Since : A Unix timestamp or strtotime data value that points to the start of the range of time-based data.

Dealing with localised DateTime in Symfony2

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.

How tell the local time of a web visitor?

I'm building a blog engine in CakePHP and I would like to show the current visitor articles relative to their local time of day.
For visitors where it's currently morning, then I'll show articles related to starting your day and news items that happened overnight.
For visitors where it's currently evening, then I'll show articles that recap the highlights of major events during the day.
The only possible solution I can think of is to send their current timezone via Javascript to the server, but this can only happen after the web page has loaded. How can I did this at the time the CakePHP application renders the pagination view for index action?
Not exactly sure about php, However this will work in all language.
You better store difference in GMT for user using
i copied syntax from internet
var d = new Date()
var n = d.getTimezoneOffset();
now at very first page, run this code on page load and store value of n in DB using ajax or whatever.SO whenever your user login you get the time diff till he/she logout.Use that DB value (store in session for better use) to further process.
Further create function like
addGMTDiff()
{
// fetch stored value for difference and return
}
call this function after every sql query that fetched UTC time.

Categories