I have an issue on a Heroku server. Saving a unix timestamp to my DB using moment.js on my local server functions correctly. However on Heroku the timestamp is 23 hours behind, rounded down to the nearest hour.
dateProvided = Number(moment($('#dateProvided').val(), 'DD/MM/YYYY').unix())
The value provided by $('#dateProvided').val() is "12/08/2017". The unix timestamp for both the local and Heroku server is "1502492400" which is "08/11/2017 # 11:00pm (UTC)" when converting.
Return value
When I want the value that has been saved the code is:
moment.unix(dateProvided).format('DD/MM/YYYY')
Browser
The code above returns the correct date "12/08/2017" on the browser.
Heroku server
The code above returns the incorrect date "11/08/2017" on the Heroku server.
The issue was my local timezone was being used as the unix timestamp and Heroku is on UTC timezone. Therefore when saving Heroku was differing. The solution is:
moment.utc(value, 'DD/MM/YYYY').unix()
This ensures the timezone is the same as Heroku when saving a timestamp.
Use the module moment-timezone as this handles all types of timezones around the world. It fixed my problem with Heroku date/times.
Example:
const date = moment().tz('Europe/London').format('DD/MM/YYYY');
Further info: https://momentjs.com/timezone/
Related
After following the procedure noted in this answer to change server time zone for a dyno the timestamp was still showing UTC using the command heroku log --tail or viewing logs on the application dashboard.
For example a Heroku contributor was trying to set IST via TZ="Asia/Kolkata, and I have done the same using TZ=America/New_York. However the timestamp in the log remains UTC regardless of the time zone chosen in the TZ environment variable.
As documented here, the TZ environment variable will not affect logs. Heroku logs are always timestamped in UTC.
I'm running Grafana 4.1.0_beta1 and Elasticsearch 5.1.1.
All my servers are setup for Mountain Time, I seem to be running into an issue where Grafana attempts to "account" for UTC, and offsets search parameters by 7 hours.
As an example;
date result from server; Wed Jan 4 20:10:54 MST 2017
But when I try to add and test a data source in Grafana, I get this error:
{"root_cause":[{"type":"index_not_found_exception","reason":"no such index","resource.type":"index_or_alias","resource.id":"metricbeat-2017.01.05","index_uuid":"_na_","index":"metricbeat-2017.01.05"}],"type":"index_not_found_exception","reason":"no such index","resource.type":"index_or_alias","resource.id":"metricbeat-2017.01.05","index_uuid":"_na_","index":"metricbeat-2017.01.05"}
While metricbeat-2017.01.05 does not exist, metricbeat-2017.01.04 does as it should.
When on a dashboard, I don't see any data, until I set the time, to anything over 7h prior.
I didn't see anything regarding timezone in the elasticsearch, or grafana config files.
Am I missing something?
Classic case of over analyzing.
It looked like everything was correct because it was, except for my client timezone.
Correct Timezone on local client
Ensure time is updated correctly
Restart web browser
You should be able to time shift the data back into range by 7h by going into added panel widget -> Time range -> Add time shift.
--If nothing else works that is.
What timezone does Heroku's servers use? I'm trying to use node-cron and have the timezones line up, but I can't understand what timezone Heroku is using. Here's an example.
2015-11-30T09:16:45.874086+00:00
By default Heroku will return calls for current time in UTC.
You can manually set your app's time zone by adding a TZ environment variable via the config command. Keep in mind that you must use the tz database time zone format. For example, if you wanted to set your default time zone to US Central time you would use the following command (I'm assuming you have/use heroku toolbelt) :
heroku config:add TZ="America/Chicago"
EDIT: As treecoder points out in the comment below; the TZ ENV variable can be added via the Heroku dashboard if you prefer. Open your app's dashboard and navigate to the 'settings' tab, then under 'config variables' click the 'reveal config vars' button. You will then be able to add TZ = America/Chicago (or whatever timezone you need).
NOTE: The TZ environment variable does not affect logs. See the second note here.
Heroku is UTC by default. Open your app in heroku and go to app setting and click on Reveal Config Vars as in image
and you have to add var as in image
TZ=Asia/kolkata
Then it will work fine for INDIA time zone. you can choose your time zone from time-zone-list.
Heroku is UTC by default. You can change it by setting an env var to TZ=America/New_York or whatever, but I highly recommend you don't.
It's really good practice to keep all your server stuff (Heroku, CMS, etc.) in sync at UTC, and to only change this when displaying times clientside with something like Luxon.
Keeping this stuff in sync will save you a lot of headaches.
According to this, Heroku Help Log, you can change it with TZ variable. However, this never changes your log times, as they are always UTC.
I using some side api on my server what written in Ruby, and I found problem that timezone in Ruby app is different from my (on server sets proper timezone), I try to find solution how to configure it (like in php.ini) but I only getting results to set it in code. Can somebody tell me can I configure it like in PHP, e.g. in some ruby.ini file? Thanks!
Ruby gets the time zone information from the host's operating system. So you can either:
Change the time zone on your OS, or
Set the TZ environment variable. Eg.
ENV['TZ'] = 'US/Eastern'
source
Is there a way to have my online application get the time and date from the user local machine instead of the server it resides on? The point is that there are users in different time zones and it will not make sense to have the standard UTC time stamp on their files. Thanks in advance fo ryour help.
Yes, with JavaScript new Date().