Navigating the challenges of time zones when calculating lag times

I am currently attempting to calculate the lag in milliseconds between my client (located in France) and my server (based in Germany).

On the Client side (Using Angular Typescript) :

this.http.getDate().subscribe(response => {
               if (response.type === HttpEventType.Sent) {

           const dateSent = new Date();
            const dateOffset = dateSent.getTimezoneOffset();
            const timeSent = dateSent.getTime() + dateOffset;
            console.log(timeSent);

    } else if (response instanceof HttpResponse) {


          const dateReceived = new Date(response.body.dateReceived);
          const timeReceived = dateReceived.getTime();
          console.log(timeReceived);
        }
      });

On the Server side (Using Java) :

return new Date();

timeSent = 1559221214039 and timeReceived = 1559221212914

Why is there a difference of -1125‬ milliseconds between them? According to Firefox's developer tool, the network indicates it took 200ms.

If anyone could provide insight on what might be going wrong, it would be greatly appreciated.

Thank you for your assistance.

Answer №1

The Javascript method getTimezoneOffset() is used to retrieve the time-zone offset in minutes for the specific locale. This offset represents the difference in minutes between the local time and Greenwich Mean Time (GMT).

For instance, if the time zone is GMT+10, the method will return -600. It's worth noting that this value is affected by daylight savings time and may not always be constant.

Learn more about Javascript date.getTimezoneOffset() here.

Don't forget to multiply by 60*1000.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

How to create an Ion-select element with dynamic options in Ionic 2?

Currently, I am working on an application in Ionic 2 and I am facing a challenge with adding ion-select options dynamically. Below is the snippet of my code: <ion-select [(ngModel)]="classifications" (ngModelChange)="updateSelectedValue($event)"> & ...

What is the best way to show mat-select choices above a dialog box?

In my quest to find a solution, I came across this approach in the global css file: .cdk-global-overlay-wrapper, .cdk-overlay-container { z-index: 10000; } However, this method seems to cause issues with other dialog windows (such as the MatDatepicker ...

Execute a Java program using the Windows command prompt

As someone new to the world of Java development, I am currently working on a project for school. This is my very first post on SO and I am encountering two related issues. Firstly, I am facing the "Error: Could not find or load main class Main" message whe ...

Guide on Implementing Link href in Next.js v12

When I set the href as a string, the link functions properly. However, when I use an object for the href, the link fails to work. Despite seeing the correct querystring when hovering over the link, it always takes me back to the first page. // ProdCard t ...

Encountering an error while running a selenium test on the QAT server using Jenkins, but the test runs smoothly on the local Jenkins environment

Currently, I am working on automating a project by writing tests using Selenium and Java. The tests run smoothly when executed from Jenkins on my local server, but I encounter an error when running them on the QAT server. In the past, I wrote Selenium test ...

Using TypeScript with Vue allows you to customize the default export of Vue

Currently experimenting with Vue and TypeScript, attempting to compile to AMD in my tsconfig file. The type definition in vue/types/index.d.ts for Vue.js includes: export default Vue; However, this results in TypeScript compiling it like this: import V ...

Unlocking Column Data Tooltips in Angular Datatables: A Step-by-Step Guide

I have a single datatable and was wondering how to implement tooltips for when hovering over table cells. I tried the following code snippet, which successfully populated the tooltips. However, I am interested in achieving the same functionality using Angu ...

Guide to uploading a recorded audio file (Blob) to a server using ReactJS

I'm having trouble using the react-media-recorder library to send recorded voice as a file to my backend. The backend only supports mp3 and ogg formats. Can anyone provide guidance on how to accomplish this task? Your help would be greatly appreciated ...

Dispatch a POST request from the Spring controller

Question time! Let me paint the picture for you. We've got a jsp page with a post form and a few inputs. Now, when a user enters data and hits that submit button, my spring controller steps in, processes the incoming data, and now I need to send that ...

Converting a JSON object into a text format

Seeking advice on a web application I'm developing where a REST service is receiving a JSON string. The JSON string structure is as follows: { "string" : "value", "string" : "value", "object" : { "string" : "value", ...

The process of adding new files to an event's index

I'm trying to attach a file to an event like this: event.target.files[0]=newFile; The error I'm getting is "Failed to set an indexed property on 'FileList': Index property setter is not supported." Is there an alternative solution fo ...

Error: Unable to cast java.lang.Boolean to java.util.Map

I encountered an issue on this specific line of code: "Map map = (Map) dataSnapshot.getValue();" private void retrieveAssignedCustomer(){ String driverId = FirebaseAuth.getInstance().getCurrentUser().getUid(); DatabaseReference assignedCustom ...

Warnings when compiling Angular with declarations of Angular Material components

Recently, I've been encountering numerous warnings during compilation after installing Angular Material. The warnings persist whether I install it directly from npm or through ng add @angular/material, regardless of whether I opt to use animations or ...

In Angular, why might a change event fail to trigger while a similar DOM event listener works?

My angular application includes a component with a file input as shown below: <input #fileInput type="file" (change)="uploadFile($event)" /> This component is utilized in various parts of the application and usually functions as ...

What is the best strategy for managing a sizable react application using react-query?

Since diving into React with functional components and react-query, I've been facing some confusion on how to properly organize my components. Typically, I design components by having a top-level component handle all data access and pass data down to ...

Utilizing the 'create' function in sqlite each time I need to run a query

I've been diving into SQLite within the Ionic framework and have pieced together some code based on examples I've encountered. import { Component } from '@angular/core'; import { IonicPage, NavController, NavParams } from 'ionic-a ...

Can you provide some instances of attribute directives?

I'm struggling to understand when it's best to implement an attribute directive, know when an attribute directive is necessary, utilize input and output properties Why should I use an attribute directive? I often find myself combining all l ...

Load components dynamically by fetching them as variables

Currently, I am working on a rather intricate component loader project in Angular, and my goal is to dynamically retrieve the component instance from an rxjs store. loadEditAreaComponent(component: any, componentInstanceData?: {}){ const componentFacto ...

Creating robust unit tests for Node.js applications with the help of redis-mock

I am facing an issue while trying to establish a connection with redis and save the data in redis using the redis-mock library in node-typescript, resulting in my test failing. Below is the code snippet for the redis connection: let client: RedisClientTyp ...

What is the best way to transfer data from a modal with a form in Ionic 2 to the home page?

Hello everyone, I could really use some assistance. As a newcomer to Ionic and Angular, I am attempting to develop a weather app in Ionic 2. I have set up a Home page that triggers an AddWeather() function through a Click event. The function opens a modal ...