In vanilla forum, message time and post time is displayed wrong - php

In forum whenever anybody messages or posts something, the time is displayed wrong, it is showing half an hour back time. The default timezone is set as "UTC" and for India timezone is "UTC+05:30". I tried to change it to "UTC+05:30" and "Asia/Kolkata" but it didn't work. I think this function date_default_timezone_set() will not accept "UTC+05:30" but "Asia/Kolkata" is also not working for me.

Related

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

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.

php - How to generate correct unixtimestamp for facebook api for scheduled posting on a wall?

I've checked some previous questions in this subject but couldn't find a suitable solution for this .it seems very small problem , but strange one. The problem :
I've create a php script to post on a users facebook pages using facebook php sdk. It works correctly when I want to publish my post on page directly. But I'm incurring an error when I set "scheduled_publish_time" for that. The error :
(#100) The specified scheduled publish time is invalid.
I think, I'm generating the unix timestamp correctly for this option.But can't find the problem . here is my code :
date_default_timezone_set('Americas/New_York');
$date = strtotime("now +10 minute");
//posts message on page statues
$msg_body = array(
'message' => $userMessage,
'published' => 'false',
'scheduled_publish_time' => $date
);
I'll be thankful if anyone could help me.
I'm not much of a programmer but shouldn't you set your timezone to America/New_York?
Without the s in Americas, check Supported timezones for America.
And you might need to use parentheses to use the now function e.g. now()
I had the same problem, and then I looked at documentation on FB developer site
The scheduled_publish_time parameter should be included when
publishing a Page post, and it should be a UNIX timestamp that is
between 10 minutes and 6 months from the time of publish.
Your date is not correct. You need to provide valid timestamp which is current time + at least 600s. Please be aware that because of latency it could be problem if you specify 600 and in time it arrives to Facebook it is +599 and post will not be published.
Other problem is how you are using date function.
If you prefer to use human readable syntax then use this
strtotime("+10 minutes")
but better
strtotime("+11 minutes")
or
time()+3610; //I have added 10s more to avoid problems with processing

Time Zone issue in Joomla Virturmat 2.x

I faced an issue for setting the default time zon in my Joomla shopping cart site.
I am using Joomla 1.7 and VM2.0.6 .
I can set the default time zone from the Joomla administrator but in the VM this time zone is not getting/saving in DB.
I have to set the time zone correctly for orders and registration the VM using a function for getting the time zone.
vmJsApi::date("Y-m-d h:i:s ",'LC2',true);
Did anybody have some idea about this function it will return the result in 24h format i want that in 12hr and correct the time .
Any link to reference or hint will appreciated.
Thanks in advance..

Time zone handling in 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

Categories