I'm using the TimeAgo plugin to update the time of posts automatically. It makes time like 05-08-2014 15:02:39 to 5 minutes ago.
The problem is, the javascript uses client's clock for time. I'm from Bangladesh, Asia. But in php the default timezone varies from server to server. I'm outputting the format 05-08-2014 15:02:39 in PHP to convert it into something like 5 mintues ago using the TimeAgo plugin.
Because server's timezone is different, instead of showing less than a minute ago on a recent post, it shows nn hours ago. If the server is american, it shows 11 hours ago, if it's indian, the time shows 30 minutes ago. How do I fix it?
As stated on the TimeAgo project page:
Are you concerned about time zone support? Don't be. Timeago handles
this too. As long as your timestamps are in ISO 8601 format and
include a full time zone designator (±hhmm), everything should work
out of the box regardless of the time zone that your visitors live in.
So echo the dates server side with date('c',$timestamp) and everything should work fine.
Related
I am working on a node.js app that is pulling a date from a sql server database, the date comes out of the database correctly, but when processed in the javascript it ends up a day prior. I have tried manually parsing the date, the date-format package and moment.js all of which take a day off. I initially thought it was time zone related after I tried a datetime variable and it was off by 5 hours. So my theory was that it was incorrectly assuming time zone. However my timezone is EST which is UTC-4 currently.
Code
const m = require('moment')
const callDate = m(summary.callDate).format('MM/DD/YYYY');
console.log(summary.callDate)
console.log(callDate)
Output
2019-10-21T00:00:00.000Z
10/20/2019
I think it may be applies the server timezone by default. So to unify all dates you may want to use moment.utc(dateObject).format();
Directly as the titles says,
I tried new Date() on my app, even on an online editor.
And the result was an incorrect value of time and day (7 hours late). Other than that the Greenwich Mean Time that is shown is actually correct (GMT + 7). So at the time, I wrote this.
That is an online Javascript editor that can be found here. And if you look at the top-right, that's the time of my local computer. And the correct date and time. However, the code editor says otherwise. I tried it on my local computer too using nodejs. But it's the same result.
The Question
Is this a bug?
How do I get the accurate time and date for my application without the help of a library?
Thank you.
I want to use this packet to work with cookies in my web app
https://github.com/js-cookie/js-cookie
In my web app my task is to extend the expire time (15 minutes) of cookie when user is do some actions.
To extend the expire time I use this guide:
https://github.com/js-cookie/js-cookie/wiki/Frequently-Asked-Questions#expire-cookies-in-less-than-a-day
My question is, does this code, that use getTime() function (return time always in UTC) correct work with users what use another time zone?
For example if user have CST time zone (different by 6 hours of UTC), the cookie is expired correct (15 minutes) or not (6 hour 15 minutes)?
If not, have you any ideas how to improve this code? Thanks.
Date#getTime
getTime() always uses UTC for time representation. For example, a client browser in one timezone, getTime() will be the same as a client browser in any other timezone.
The timestamp is always in UTC.
For example if user have CST time zone (different by 6 hours of UTC), the cookie is expired correct (15 minutes) or not (6 hour 15 minutes)?
No, because the time is in CST and not UTC, also in the quote from above "getTime() will be the same as a client browser in any other timezone".
There is no problem with timezone here. The example code will work fine.
If you want to simulate what happens in other timezones, just change your system's timezone setting. In windows, right-click on the clock and choose "Adjust date/time".
If you look in at the set-cookie header in the response, you'll see an expires attribute in UTC. Browsers know perfectly well how to deal with UTC. So long as their own clock and timezone are set correctly, everything will work as expected. This is very fundamental stuff. There are no problems here !
Javascript dates have no notion of timezone, so there is no such thing as a UTC Date object in javascript. The entire contents of your Date object are revealed when you call getTime() - it's just a number, so getTime() has no notion of timezone either. new Date() gives you a number representing the present instant. Once again, no notion of timezone. It does the same thing everywhere.
I am looking for javascript/jquery digital clock script in 24 hour format with Date. The clock should display images as its numbers and date; also the clock should initialize its time from a hidden field having server time. I am using asp.net.
In all seriousness, how much searching did you do? I simply typed 'jquery digital clock' into google and got loads of results, here's one in particular:
http://www.jquery4u.com/plugins/10-cool-jquery-clock-tutorials-analog-digital/#.UCjA_SLYEpo
I'm adding a facebook feed to a jquery mobile application i am working on. I am trying to parse the "created_time" that is in the JSON data. This is what is in the returned JSON: 2011-01-29T16:30:03+0000. I would really love to have the data returned and displayed the same way that facebook has it. That would mean that if the post was less than an hour ago it would display as ## minutes ago, if it was more than an hour ago but less than a day ago it would display as ## hours ago, otherwise it would display as February 2 at 6:54pm. I would love some help with this! Thanks a lot!
Try pretty date from the author of jQuery. Available standalone or as a jQuery plugin.
By default it doesn't format dates older than a month, so you may want to edit this to ignore after X hours/days rather than months.