I've got a pretty simple question. I send a date as millis created by javascript to a php site and use phps getdate to get information about the date in an associative array. My timezone is GMT+2, but I do not understand why date conversion using milliseconds should have any effect like this. Can someone please explain this to me?
Thanks!
It sounds like PHP doesn't know what the timezone is supposed to be or the system timezone is not properly set. The simplest fix is to set the timezone you want yourself in the PHP code.
Related
I am having trouble in the timestamp.
When I am using the LAMP in Ubuntu, then it works with correct date which I entered, but on other systems it show 1 day back's date.
I don't know what I need to do now. I have stored the timestamp in my database. But when I am showing it on my web application, it works fine in the LAMP but not in others.
When I am converting the timezone to online converter it shows backdated result. What do I do now?
You can set PHP default timezone before reading the date from the timestamp.
Add the following line before reading the date.
date_default_timezone_set('Asia/Calcutta');
Let me know if this helps.
References:
http://php.net/manual/en/function.date-default-timezone-set.php
http://php.net/manual/en/timezones.php
The timestamp stored is correct, Please set the default time zone in your PHP application to let the system know which timezone you are using then it will store the correct time zone. the below link would help you.
I am assuming you are storing timestamp in DB and retrieving it to display
http://php.net/manual/en/function.date-default-timezone-set.php
Thanks
Hi I have posted this question before, but people marked it as a duplicate questions. so I didn't get any answer.
I am trying to get the current date/time in the format for example "20150701183741.941Z', I am not sure what the technical term for this format is called. some people told me that it is UTC/ZULU time format.
I have tried generate the above format by using below codes.
date_default_timezone_set("UTC");
echo "formatted currenttime: ".date("YmdHis.ue", time());
but it returns it in the format "20150701144710.000000UTC", this is close to what I need, but I am not able to get at the end something similar to ".941Z".
Please note that this isn't a duplicate question. I posted it earlier but got marked as a duplicate and that one is now inactive. Thanks very much for your help.
The official documentation of date() says that date() always generates 000000 because it takes an integer parameter, and that DateTime() does support microseconds:
http://php.net/manual/en/function.date.php
However, this comment seems to say that DateTime() doesn't support microseconds either:
http://php.net/manual/en/class.datetime.php#108970
So I guess you're out of luck with that :(
Why don't you use the Carbon Library? It's one of the superb ways to handle data and time. Just take a look into the official documentation at http://carbon.nesbot.com/docs/
I'm having an issue with the FileMaker PHP API. I don't know how to format a time correctly for input into a Time field.
I tried entering a string with the format that the documentation guide says (H:M where H can be 24 hours) and it still doesn't take. I don't know if I'm supposed to change the data type with another function like date() or what.
Edit: A little snippet of code
//Date
if($arrDate!=NULL){
$booking->setField('arrival_date', '07/17/2015');
}
//Time
if($arrTime!=NULL){
$booking->setField('arrival_time', '11:00:00');
}
$savedBooking = $booking->commit();
I replaced the variables for the value fields with what they should be just in case it was something going wrong with them, but it still doesn't work. The date field setting works fine if I comment out the Time section however.
Here's the format that I use:
$booking->setField('arrival_date', date ( "n/j/Y H:i:s A" ) );
If you're interested in adjusting the time, here's a post to checkout: http://timdietrich.me/blog/php-timezone-arithmetic/
Good luck!
I suspect you may have some validation set up on the "arrival_time" time field. What is the error that is returned by the API? It should return an error code that will tell you more.
Also worth mentioning that FileMaker will inherit the date and time settings from your system settings. For example, date formats are different in Europe than they are in the states. But that time value you give looks like it would work, and you only get an error when setting that field, so I would look to make sure the field is defined correctly.
You can also test by putting that value in via FM Pro and see what happens.
I'm an idiot, after hours struggling with this I realized I had put the wrong field name! Thanks for your help guys. A string of H:M worked perfectly.
How to get correct date not by system date in php
For ex: actual date is 24/4/2013, but I changed my system date is 25/4/2013.
How can get correct date ie 24/4/2013?
PHP can't inherently know that your system time is incorrect. As others have pointed out, you can query an authoritative source (similar to the solution offered here) instead.
EDIT: shortcut to the time server query example
http://tf.nist.gov/tf-cgi/servers.cgi
,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
Set the default time zone prior to use the date() function.
For instance:
date_default_timezone_set('UTC');
// or
// date_default_timezone_set('Europe/Madrid')
echo date("Y-m-d H:i:s");
Timezones and timestamps confuses me so I'm hoping someone can answer my questions :)
Lets say I have a Python script that parses an RSS feed, converts the date value into a timestamp using the following code and stores it in a database:
article_date = parse(article.published).strftime('%s') if hasattr(article, 'published') else round(time.time())
Now when I retrieve that record from the db in PHP, and I run the following code, does PHP assume the timestamp was UTC-0 and automatically offsets the timezone to Eastern time?
date_default_timezone_set('America/New_York');
echo date('Y-m-d H:i:s',$timestamp);
I'm seeing weird issues with my dates, so I'm wondering if someone can help me out with advice on how to properly convert and store rss feed timestamps. I can across this line of code somewhere so should I put this at the top of my script?
os.environ['TZ'] = 'Europe/London'
If you want to set your timezones and keep them aligned in PHP and in Python, then your PHP code is completely correct and for python you need to apply the following:
os.environ['TZ'] = 'America/New_York'
time.tzset()
before you call strftime()
That should make sure you store the time in the same zone you're trying to retrieve it.
Note: tzset() is a Unix-only function.