Timezone dating operations

When a user selects a date on the client side using a date picker, I need to send it to the server and use UTC value for future calculations. For example, if the user chooses "Tue Oct 04 2011 00:00:00 GMT+0300 (E. Europe Daylight Time)," I send milliseconds to the server using "date.getTime()." On the server, I have a method:

public static DateTime GetDateByMilliseconds(long milliseconds)
{
    var date = new DateTime(1970, 1, 1);
    return date.AddMilliseconds(milliseconds);
}

The result I get is "Oct 03, 2011 09:00:00 PM," but what I actually want to work with is "Oct 04 2011 00:00:00." Do I need to reset the date timezone on the client side or add an offset on the server? Is there anything else I should consider?

Answer №1

My suggestion for this situation would be:

date.getTime() + (date.getTimezoneOffset() * 60 * 1000)

By applying this code, you will effectively eliminate the offset based on the user's timezone.

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

Distinguish between closing a browser tab and refreshing it to identify various instances of the application

How do you differentiate between browser tab close and refresh functionality? Currently, window refresh and close events do not have separate events. My requirement is to check whether the user is already logged in on any tabs, so that I can prevent th ...

Personalizing the success message of a function in node.js

I received this node.js code for an IBM Cloud function that allows a user of my Watson Assistant to send me email reminders. It's working flawlessly. var nodemailer = require('nodemailer'); let smtpConfig = { host: 'hosthere', ...

ASP.NET Active Directory authentication provider

This is the first time I've delved into ASP.NET Role membership in active directory. Currently, my website is up and running, and I am able to log in with an active directory user successfully. However, I'm facing an issue where "Roles.IsUserIn ...

Merge various JavaScript files together into a single consolidated JS file

I've been working on my web application with jQuery and am looking to incorporate multiple additional jQuery script files into one page. After doing some research, I found that Google recommends consolidating all of the jQuery script files into a sin ...

Angular 4.0 has discontinued the use of the ngGetContentSelectors() method

There has been a deprecation of the method ngGetContentSelectors() in Angular 4.0. Can you suggest an alternative for this? ...

Vue: Implementing conditional styling in table cells

Currently, my vue function involves using nested v-for loops to iterate through an object and create a table with rows and cells. While this method is effective, I am now faced with the challenge of implementing a v-if statement in the innermost loop to co ...

Is it possible in Visual Studio 2022 to configure an editorconfig file at the solution level, as well as at the project level to override

Is it possible to set up a solution-wide .editorconfig file in Visual Studio 2022 and then have project-specific .editorconfig files that can override or add to the settings defined in the solution-wide file? In my scenario, I need different configuration ...

Error: Vue.js is unable to find the reference for "_vm.KisanData" and throws a TypeError

I need assistance in fixing an error that I am encountering. The issue arises in this method where I am using KisanData, but I am unable to resolve it. const API_URL = "http://localhost:3000/User"; export default { name: "home", info(){ ...

What are the different techniques for implementing React-Redux? Comparing Redux-thunk and Redux-Saga

My understanding of Redux is still quite hazy as I delve into various techniques and methods. I am curious to learn about other methods similar to redux-Thunk and redux-saga. Each utilizes distinct functions such as CreateSlice. I am interested to know w ...

Using regex in a contenteditable div, JQuery can remove multiple instances of <p> tags simultaneously

I am currently working on a project that involves removing multiple empty paragraphs using jQuery and regex within a contenteditable div. However, I have encountered an issue that I need help with. To see an example of what I'm trying to accomplish, y ...

Converting a variable with a cloned object from jQuery to vanilla JavaScript

const clonedBoardCode = $('#board_code').contents().clone(false); alert( clonedBoardCode.filter('div').eq(x).children().eq(y).text() );//need to fix this I am looking for a code similar to this $('#board_code_dup > div') ...

Utilizing the default event object in ag-Grid's event methods with JavaScript

I am a newcomer to ag-grid and I need help with calling event.preventDefault() in the "cellEditingStopped" grid event. Unfortunately, I am struggling to pass the default JavaScript event object into it. Is there a way to make this work? Additionally, I al ...

What is the process for extracting the value of a particular column within a table?

Looking to extract information from a specific column in each row? I have a table displayed here: Table Image. My goal is to retrieve the model name from the "Model" column. I have a database and a "SELECT" query set up based on the "Model" displayed, whi ...

Guide to showcasing images dynamically within a table

I am currently working on a dynamic table that updates its data using a script. My goal is to also display corresponding images of the groups next to their names in the table. Whenever the group names change, I want the images to change as well. The funct ...

What could be the reason for the empty array returned by the combinationSum function in Javascript?

The combinationSum function is returning an empty resultArr. When checking the ds array with console.log, it shows the correct answer, but for some reason, the final output array ends up being [[],[]]. var combinationSum = function(candidates, target) { ...

Not enough test coverage with Jest

Here is the code snippet I am working with: <ReturnToLastSearch href={'/listings'} onClick={(e): void => { e.preventDefault(); router.back(); }} /> The function ReturnToLastSearch( ...

I encountered a ReferenceError stating that the variable "req" is not defined when I try to

I am currently developing a login application using React.js and Node.js (Express, JWT), but I am facing an issue when trying to export my function. I keep receiving the error ReferenceError: req is not defined, even though I have defined req. How can I re ...

Generate a Java .dll file from the existing .net dll

Currently, I find myself at a crossroads. There's a .dll file that was developed in .NET using SWIG(), and my aim is to utilize this dll in Java. My inquiries are as follows: Is it possible to directly use the dll file? In other words, is the dll ...

What is the reason behind my page automatically scrolling to the bottom when it loads?

I am currently working on a project for my company, and unfortunately, I cannot share the code as it is proprietary. However, I am encountering a problem where the page loads and automatically scrolls to the bottom. I have checked for any unclosed tags in ...

Strategies for resolving duplicate jQuery code in my project

Trying to simplify my jQuery code that handles video selection and playback functionality. Users can click on a thumbnail or button to play a specific video, with the title of the video changing accordingly. Despite achieving the desired outcome, the cur ...