Javascript : evaluate delta between UTC and Central Europe Time2019 Community Moderator ElectionConvert UTC/GMT time to local time“date_part('epoch', now() at time zone 'UTC')” not the same time as “now() at time zone 'UTC'” in postgresqlHow to convert time correctly across timezones?R - Reading ISO8601 formatWhy are timezones with same offset from UTC are showing different times?Getting a date and time input in Eastern Time and converting to UTC timestamp in JavaConverting UTC to local time doesn't work in javascriptJava Calendar and Time UTC to BSTBehaviour of GregorianCalendar.set() with daylight saving timesCreate time entry in Firestore with UTC 0

What has been your most complicated TikZ drawing?

Do Bugbears' arms literally get longer when it's their turn?

Time dilation for a moving electronic clock

Rejected in 4th interview round citing insufficient years of experience

What is the dot in “1.2.4."

Time travel short story where dinosaur doesn't taste like chicken

What does it mean when multiple 々 marks follow a 、?

Playing ONE triplet (not three)

Is all copper pipe pretty much the same?

Do I need to leave some extra space available on the disk which my database log files reside, for log backup operations to successfully occur?

Is it illegal in Germany to take sick leave if you caused your own illness with food?

When were linguistics departments first established

Best approach to update all entries in a list that is paginated?

Is having access to past exams cheating and, if yes, could it be proven just by a good grade?

Co-worker team leader wants to inject the crap software product of his friends into our development. What should I say to our common boss?

Can infringement of a trademark be pursued for using a company's name in a sentence?

If Invisibility ends because the original caster casts a non-concentration spell, does Invisibility also end on other targets of the original casting?

Ban on all campaign finance?

Why would a jet engine that runs at temps excess of 2000°C burn when it crashes?

Making a sword in the stone, in a medieval world without magic

When two POV characters meet

What is the difference between "shut" and "close"?

Is going from continuous data to categorical always wrong?

redhat 7 + How to stop systemctl service permanent



Javascript : evaluate delta between UTC and Central Europe Time



2019 Community Moderator ElectionConvert UTC/GMT time to local time“date_part('epoch', now() at time zone 'UTC')” not the same time as “now() at time zone 'UTC'” in postgresqlHow to convert time correctly across timezones?R - Reading ISO8601 formatWhy are timezones with same offset from UTC are showing different times?Getting a date and time input in Eastern Time and converting to UTC timestamp in JavaConverting UTC to local time doesn't work in javascriptJava Calendar and Time UTC to BSTBehaviour of GregorianCalendar.set() with daylight saving timesCreate time entry in Firestore with UTC 0










0















I have a server app in Firebase cloud function with webhooks that receive data from a third party API.
In those data, I have times expressed in HH:mm local time (Central Europe Time).
I need to store them in Firestore as a timestamp UTC.



I tried this:



 //Evaluate offset between CET and UTC
const dAujourdhui = new Date(); //07/03/2019 10:39 (UTC)
const nHeureUTC = dAujourdhui.getUTCHours(); //10
const nHeureLocal = dAujourdhui.getHours(); //10
const timeZoneOffset = nHeureUTC - nHeureLocal //0!

// Build a timestamp based on today's date and received time
const currentDateString = dateFormat(dAujourdhui, "yyyy-mm-dd");
var estimatedDateTimeOfArrival = new Date(`$currentDateString $timeReceivedFrom3rdPartyAPI`);

// Add offset to hours
const utcHour = estimatedDateTimeOfArrival.getUTCHours()
estimatedDateTimeOfArrival.setHours(utcHour + timeZoneOffset)

// Save to firestore
...


As you can see, I'm not able to evaluate the offset between CET and UTC as the code is run in a server set in UTC.



Any idea on how to solve it ?










share|improve this question






















  • What exactly do you receive? Please provide an example. Also, you have a dateFormat function - is that coming from a library? Which one? Lastly, when you save to firestore at the end, what are you saving? Do you pass a Date object or a string in a particular format to some API? which one? As you can see, without a Minimal, Complete, and Verifiable Example, it's difficult to provide assistance.

    – Matt Johnson
    Mar 7 at 18:41






  • 1





    A couple things from what you provided: 1) When you add the offset to the hour, you're not adjusting for time zones but rather you're picking a different point in time. 2) JavaScript already has a getTimezoneOffset function that does what that first block of code does, but that won't help you here. 3) The offset from UTC may be different depending on the date you apply it to, such as when summer time is in effect. 4) You may end up needing a library such as Luxon or Moment-Timezone, depending on your input string.

    – Matt Johnson
    Mar 7 at 18:46











  • Thanks Matt Johnson. Indeed, I figured out that I need to go for an external library. I have been able to solve the problem with 'moment-timezone'

    – Laurent Maquet
    Mar 8 at 8:42















0















I have a server app in Firebase cloud function with webhooks that receive data from a third party API.
In those data, I have times expressed in HH:mm local time (Central Europe Time).
I need to store them in Firestore as a timestamp UTC.



I tried this:



 //Evaluate offset between CET and UTC
const dAujourdhui = new Date(); //07/03/2019 10:39 (UTC)
const nHeureUTC = dAujourdhui.getUTCHours(); //10
const nHeureLocal = dAujourdhui.getHours(); //10
const timeZoneOffset = nHeureUTC - nHeureLocal //0!

// Build a timestamp based on today's date and received time
const currentDateString = dateFormat(dAujourdhui, "yyyy-mm-dd");
var estimatedDateTimeOfArrival = new Date(`$currentDateString $timeReceivedFrom3rdPartyAPI`);

// Add offset to hours
const utcHour = estimatedDateTimeOfArrival.getUTCHours()
estimatedDateTimeOfArrival.setHours(utcHour + timeZoneOffset)

// Save to firestore
...


As you can see, I'm not able to evaluate the offset between CET and UTC as the code is run in a server set in UTC.



Any idea on how to solve it ?










share|improve this question






















  • What exactly do you receive? Please provide an example. Also, you have a dateFormat function - is that coming from a library? Which one? Lastly, when you save to firestore at the end, what are you saving? Do you pass a Date object or a string in a particular format to some API? which one? As you can see, without a Minimal, Complete, and Verifiable Example, it's difficult to provide assistance.

    – Matt Johnson
    Mar 7 at 18:41






  • 1





    A couple things from what you provided: 1) When you add the offset to the hour, you're not adjusting for time zones but rather you're picking a different point in time. 2) JavaScript already has a getTimezoneOffset function that does what that first block of code does, but that won't help you here. 3) The offset from UTC may be different depending on the date you apply it to, such as when summer time is in effect. 4) You may end up needing a library such as Luxon or Moment-Timezone, depending on your input string.

    – Matt Johnson
    Mar 7 at 18:46











  • Thanks Matt Johnson. Indeed, I figured out that I need to go for an external library. I have been able to solve the problem with 'moment-timezone'

    – Laurent Maquet
    Mar 8 at 8:42













0












0








0








I have a server app in Firebase cloud function with webhooks that receive data from a third party API.
In those data, I have times expressed in HH:mm local time (Central Europe Time).
I need to store them in Firestore as a timestamp UTC.



I tried this:



 //Evaluate offset between CET and UTC
const dAujourdhui = new Date(); //07/03/2019 10:39 (UTC)
const nHeureUTC = dAujourdhui.getUTCHours(); //10
const nHeureLocal = dAujourdhui.getHours(); //10
const timeZoneOffset = nHeureUTC - nHeureLocal //0!

// Build a timestamp based on today's date and received time
const currentDateString = dateFormat(dAujourdhui, "yyyy-mm-dd");
var estimatedDateTimeOfArrival = new Date(`$currentDateString $timeReceivedFrom3rdPartyAPI`);

// Add offset to hours
const utcHour = estimatedDateTimeOfArrival.getUTCHours()
estimatedDateTimeOfArrival.setHours(utcHour + timeZoneOffset)

// Save to firestore
...


As you can see, I'm not able to evaluate the offset between CET and UTC as the code is run in a server set in UTC.



Any idea on how to solve it ?










share|improve this question














I have a server app in Firebase cloud function with webhooks that receive data from a third party API.
In those data, I have times expressed in HH:mm local time (Central Europe Time).
I need to store them in Firestore as a timestamp UTC.



I tried this:



 //Evaluate offset between CET and UTC
const dAujourdhui = new Date(); //07/03/2019 10:39 (UTC)
const nHeureUTC = dAujourdhui.getUTCHours(); //10
const nHeureLocal = dAujourdhui.getHours(); //10
const timeZoneOffset = nHeureUTC - nHeureLocal //0!

// Build a timestamp based on today's date and received time
const currentDateString = dateFormat(dAujourdhui, "yyyy-mm-dd");
var estimatedDateTimeOfArrival = new Date(`$currentDateString $timeReceivedFrom3rdPartyAPI`);

// Add offset to hours
const utcHour = estimatedDateTimeOfArrival.getUTCHours()
estimatedDateTimeOfArrival.setHours(utcHour + timeZoneOffset)

// Save to firestore
...


As you can see, I'm not able to evaluate the offset between CET and UTC as the code is run in a server set in UTC.



Any idea on how to solve it ?







node.js datetime google-cloud-functions timezone-offset






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 7 at 11:02









Laurent MaquetLaurent Maquet

1489




1489












  • What exactly do you receive? Please provide an example. Also, you have a dateFormat function - is that coming from a library? Which one? Lastly, when you save to firestore at the end, what are you saving? Do you pass a Date object or a string in a particular format to some API? which one? As you can see, without a Minimal, Complete, and Verifiable Example, it's difficult to provide assistance.

    – Matt Johnson
    Mar 7 at 18:41






  • 1





    A couple things from what you provided: 1) When you add the offset to the hour, you're not adjusting for time zones but rather you're picking a different point in time. 2) JavaScript already has a getTimezoneOffset function that does what that first block of code does, but that won't help you here. 3) The offset from UTC may be different depending on the date you apply it to, such as when summer time is in effect. 4) You may end up needing a library such as Luxon or Moment-Timezone, depending on your input string.

    – Matt Johnson
    Mar 7 at 18:46











  • Thanks Matt Johnson. Indeed, I figured out that I need to go for an external library. I have been able to solve the problem with 'moment-timezone'

    – Laurent Maquet
    Mar 8 at 8:42

















  • What exactly do you receive? Please provide an example. Also, you have a dateFormat function - is that coming from a library? Which one? Lastly, when you save to firestore at the end, what are you saving? Do you pass a Date object or a string in a particular format to some API? which one? As you can see, without a Minimal, Complete, and Verifiable Example, it's difficult to provide assistance.

    – Matt Johnson
    Mar 7 at 18:41






  • 1





    A couple things from what you provided: 1) When you add the offset to the hour, you're not adjusting for time zones but rather you're picking a different point in time. 2) JavaScript already has a getTimezoneOffset function that does what that first block of code does, but that won't help you here. 3) The offset from UTC may be different depending on the date you apply it to, such as when summer time is in effect. 4) You may end up needing a library such as Luxon or Moment-Timezone, depending on your input string.

    – Matt Johnson
    Mar 7 at 18:46











  • Thanks Matt Johnson. Indeed, I figured out that I need to go for an external library. I have been able to solve the problem with 'moment-timezone'

    – Laurent Maquet
    Mar 8 at 8:42
















What exactly do you receive? Please provide an example. Also, you have a dateFormat function - is that coming from a library? Which one? Lastly, when you save to firestore at the end, what are you saving? Do you pass a Date object or a string in a particular format to some API? which one? As you can see, without a Minimal, Complete, and Verifiable Example, it's difficult to provide assistance.

– Matt Johnson
Mar 7 at 18:41





What exactly do you receive? Please provide an example. Also, you have a dateFormat function - is that coming from a library? Which one? Lastly, when you save to firestore at the end, what are you saving? Do you pass a Date object or a string in a particular format to some API? which one? As you can see, without a Minimal, Complete, and Verifiable Example, it's difficult to provide assistance.

– Matt Johnson
Mar 7 at 18:41




1




1





A couple things from what you provided: 1) When you add the offset to the hour, you're not adjusting for time zones but rather you're picking a different point in time. 2) JavaScript already has a getTimezoneOffset function that does what that first block of code does, but that won't help you here. 3) The offset from UTC may be different depending on the date you apply it to, such as when summer time is in effect. 4) You may end up needing a library such as Luxon or Moment-Timezone, depending on your input string.

– Matt Johnson
Mar 7 at 18:46





A couple things from what you provided: 1) When you add the offset to the hour, you're not adjusting for time zones but rather you're picking a different point in time. 2) JavaScript already has a getTimezoneOffset function that does what that first block of code does, but that won't help you here. 3) The offset from UTC may be different depending on the date you apply it to, such as when summer time is in effect. 4) You may end up needing a library such as Luxon or Moment-Timezone, depending on your input string.

– Matt Johnson
Mar 7 at 18:46













Thanks Matt Johnson. Indeed, I figured out that I need to go for an external library. I have been able to solve the problem with 'moment-timezone'

– Laurent Maquet
Mar 8 at 8:42





Thanks Matt Johnson. Indeed, I figured out that I need to go for an external library. I have been able to solve the problem with 'moment-timezone'

– Laurent Maquet
Mar 8 at 8:42












1 Answer
1






active

oldest

votes


















0














Here is a solution I found to solve the problem.
It is based on an external library: 'moment-timezone'



 // Example's initial setup
const dateFormat = require('dateformat')
const moment = require('moment-timezone');
const timeReceivedFrom3rdPartyAPI = "14:30" // Format "HH:mm", Paris time

// Construct Date object with today's date and timeReceivedFrom3rdPartyAPI
const currentDate = new Date();
const currentDateString = dateFormat(currentDate, "yyyy-mm-dd");
const estimatedDateTimeOfArrival = moment.tz(`$currentDateString $timeReceivedFrom3rdPartyAPI`, "Europe/Paris").toDate()

console.log(estimatedDateTimeOfArrival)
// 08/03/2018 13:30 UTC
// Now I have UTC Full Date corresponding to timeReceivedFrom3rdPartyAPI





share|improve this answer























  • Don't tack on the date. You're using the current local date, which may or may not be the same as the current date in the given time zone. Just let Moment do the work: moment.tz('14:30', 'HH:mm', 'Europe/Paris'). Also, unless you need the output to be a Date object, you're better off calling .toISOString(), or .utc().format(). (The latter would allow you to pass a format string if you want a specific format).

    – Matt Johnson
    Mar 8 at 17:08











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55042255%2fjavascript-evaluate-delta-between-utc-and-central-europe-time%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














Here is a solution I found to solve the problem.
It is based on an external library: 'moment-timezone'



 // Example's initial setup
const dateFormat = require('dateformat')
const moment = require('moment-timezone');
const timeReceivedFrom3rdPartyAPI = "14:30" // Format "HH:mm", Paris time

// Construct Date object with today's date and timeReceivedFrom3rdPartyAPI
const currentDate = new Date();
const currentDateString = dateFormat(currentDate, "yyyy-mm-dd");
const estimatedDateTimeOfArrival = moment.tz(`$currentDateString $timeReceivedFrom3rdPartyAPI`, "Europe/Paris").toDate()

console.log(estimatedDateTimeOfArrival)
// 08/03/2018 13:30 UTC
// Now I have UTC Full Date corresponding to timeReceivedFrom3rdPartyAPI





share|improve this answer























  • Don't tack on the date. You're using the current local date, which may or may not be the same as the current date in the given time zone. Just let Moment do the work: moment.tz('14:30', 'HH:mm', 'Europe/Paris'). Also, unless you need the output to be a Date object, you're better off calling .toISOString(), or .utc().format(). (The latter would allow you to pass a format string if you want a specific format).

    – Matt Johnson
    Mar 8 at 17:08
















0














Here is a solution I found to solve the problem.
It is based on an external library: 'moment-timezone'



 // Example's initial setup
const dateFormat = require('dateformat')
const moment = require('moment-timezone');
const timeReceivedFrom3rdPartyAPI = "14:30" // Format "HH:mm", Paris time

// Construct Date object with today's date and timeReceivedFrom3rdPartyAPI
const currentDate = new Date();
const currentDateString = dateFormat(currentDate, "yyyy-mm-dd");
const estimatedDateTimeOfArrival = moment.tz(`$currentDateString $timeReceivedFrom3rdPartyAPI`, "Europe/Paris").toDate()

console.log(estimatedDateTimeOfArrival)
// 08/03/2018 13:30 UTC
// Now I have UTC Full Date corresponding to timeReceivedFrom3rdPartyAPI





share|improve this answer























  • Don't tack on the date. You're using the current local date, which may or may not be the same as the current date in the given time zone. Just let Moment do the work: moment.tz('14:30', 'HH:mm', 'Europe/Paris'). Also, unless you need the output to be a Date object, you're better off calling .toISOString(), or .utc().format(). (The latter would allow you to pass a format string if you want a specific format).

    – Matt Johnson
    Mar 8 at 17:08














0












0








0







Here is a solution I found to solve the problem.
It is based on an external library: 'moment-timezone'



 // Example's initial setup
const dateFormat = require('dateformat')
const moment = require('moment-timezone');
const timeReceivedFrom3rdPartyAPI = "14:30" // Format "HH:mm", Paris time

// Construct Date object with today's date and timeReceivedFrom3rdPartyAPI
const currentDate = new Date();
const currentDateString = dateFormat(currentDate, "yyyy-mm-dd");
const estimatedDateTimeOfArrival = moment.tz(`$currentDateString $timeReceivedFrom3rdPartyAPI`, "Europe/Paris").toDate()

console.log(estimatedDateTimeOfArrival)
// 08/03/2018 13:30 UTC
// Now I have UTC Full Date corresponding to timeReceivedFrom3rdPartyAPI





share|improve this answer













Here is a solution I found to solve the problem.
It is based on an external library: 'moment-timezone'



 // Example's initial setup
const dateFormat = require('dateformat')
const moment = require('moment-timezone');
const timeReceivedFrom3rdPartyAPI = "14:30" // Format "HH:mm", Paris time

// Construct Date object with today's date and timeReceivedFrom3rdPartyAPI
const currentDate = new Date();
const currentDateString = dateFormat(currentDate, "yyyy-mm-dd");
const estimatedDateTimeOfArrival = moment.tz(`$currentDateString $timeReceivedFrom3rdPartyAPI`, "Europe/Paris").toDate()

console.log(estimatedDateTimeOfArrival)
// 08/03/2018 13:30 UTC
// Now I have UTC Full Date corresponding to timeReceivedFrom3rdPartyAPI






share|improve this answer












share|improve this answer



share|improve this answer










answered Mar 8 at 8:56









Laurent MaquetLaurent Maquet

1489




1489












  • Don't tack on the date. You're using the current local date, which may or may not be the same as the current date in the given time zone. Just let Moment do the work: moment.tz('14:30', 'HH:mm', 'Europe/Paris'). Also, unless you need the output to be a Date object, you're better off calling .toISOString(), or .utc().format(). (The latter would allow you to pass a format string if you want a specific format).

    – Matt Johnson
    Mar 8 at 17:08


















  • Don't tack on the date. You're using the current local date, which may or may not be the same as the current date in the given time zone. Just let Moment do the work: moment.tz('14:30', 'HH:mm', 'Europe/Paris'). Also, unless you need the output to be a Date object, you're better off calling .toISOString(), or .utc().format(). (The latter would allow you to pass a format string if you want a specific format).

    – Matt Johnson
    Mar 8 at 17:08

















Don't tack on the date. You're using the current local date, which may or may not be the same as the current date in the given time zone. Just let Moment do the work: moment.tz('14:30', 'HH:mm', 'Europe/Paris'). Also, unless you need the output to be a Date object, you're better off calling .toISOString(), or .utc().format(). (The latter would allow you to pass a format string if you want a specific format).

– Matt Johnson
Mar 8 at 17:08






Don't tack on the date. You're using the current local date, which may or may not be the same as the current date in the given time zone. Just let Moment do the work: moment.tz('14:30', 'HH:mm', 'Europe/Paris'). Also, unless you need the output to be a Date object, you're better off calling .toISOString(), or .utc().format(). (The latter would allow you to pass a format string if you want a specific format).

– Matt Johnson
Mar 8 at 17:08




















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55042255%2fjavascript-evaluate-delta-between-utc-and-central-europe-time%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Identity Server 4 is not redirecting to Angular app after login2019 Community Moderator ElectionIdentity Server 4 and dockerIdentityserver implicit flow unauthorized_clientIdentityServer Hybrid Flow - Access Token is null after user successful loginIdentity Server to MVC client : Page Redirect After loginLogin with Steam OpenId(oidc-client-js)Identity Server 4+.NET Core 2.0 + IdentityIdentityServer4 post-login redirect not working in Edge browserCall to IdentityServer4 generates System.NullReferenceException: Object reference not set to an instance of an objectIdentityServer4 without HTTPS not workingHow to get Authorization code from identity server without login form

2005 Ahvaz unrest Contents Background Causes Casualties Aftermath See also References Navigation menue"At Least 10 Are Killed by Bombs in Iran""Iran"Archived"Arab-Iranians in Iran to make April 15 'Day of Fury'"State of Mind, State of Order: Reactions to Ethnic Unrest in the Islamic Republic of Iran.10.1111/j.1754-9469.2008.00028.x"Iran hangs Arab separatists"Iran Overview from ArchivedConstitution of the Islamic Republic of Iran"Tehran puzzled by forged 'riots' letter""Iran and its minorities: Down in the second class""Iran: Handling Of Ahvaz Unrest Could End With Televised Confessions""Bombings Rock Iran Ahead of Election""Five die in Iran ethnic clashes""Iran: Need for restraint as anniversary of unrest in Khuzestan approaches"Archived"Iranian Sunni protesters killed in clashes with security forces"Archived

Can't initialize raids on a new ASUS Prime B360M-A motherboard2019 Community Moderator ElectionSimilar to RAID config yet more like mirroring solution?Can't get motherboard serial numberWhy does the BIOS entry point start with a WBINVD instruction?UEFI performance Asus Maximus V Extreme