How to convert a Date to OLE Automation Date in javascript [duplicate] - javascript

This question already has answers here:
What is equivalent of DateTime.ToOADate() in javascript?
(7 answers)
Closed 4 years ago.
I need to pass a Date value to a .Net server which expect to receive OLE Automation Date value (Microsoft Timestamp - a decimal value).
Any idea how to convert a Javascript Date to this format in JS?
Thanks in advance.

You can use momentjs but I don't think that's a good practice. I think it is better to pass an standard date format (like ISO) and then in your .NET application convert it to OLE Automation Date format, this way the front part is not coupled to your database.

Related

String "conversation" date format to date format in JavaScript [duplicate]

This question already has answers here:
Parsing a string to a date in JavaScript
(35 answers)
Closed 1 year ago.
I am creating a Speech to Text input engine where user will say input values for html forms. One of the input field is a type="date". Suppose the user says "July 20th 2021", Is it possible to change this date into JavaScript date format? Is there any library that does this kind of conversion?
Thanks in advance.
I would start with the Date.parse() function. If that doesn't work for you then your best bets are likely date-fns or momentJS but if your format isn't one that is immediately parseable with one of the built in functions then you may need to a bit of pre-processing yourself.

How to Convert datetime from one timezone to another timezone in Javascript? [duplicate]

This question already has answers here:
Convert date to another timezone in JavaScript
(34 answers)
How to initialize a JavaScript Date to a particular time zone
(20 answers)
Closed 3 years ago.
I need to convert from one timezone to another timezone in my project.
I am able to convert from my current timezone to another but not from a different timezone to another.
For example I am in India, and I am able to convert from India to US using Date d=new Date(); and assigning it to a calendar object and setting the time zone.
However, I cannot do this from different timezone to another timezone. For example, I am in India, but I am having trouble converting timezones from the US to the UK.
The easy and fast way is to use an external library. I recommend moment.js. once installed you can convert pretty easily and reliably through their ready-made functions

Convert Javascript date to shorter date time and also UTC [duplicate]

This question already has answers here:
Why does Date.parse give incorrect results?
(11 answers)
Where can I find documentation on formatting a date in JavaScript?
(39 answers)
Closed 5 years ago.
I have a JavaScript Date which I want to get it into SQL Server datetime field.
The JavaScript time sent over as
Fri Sep 15 2017 00:11:44 GMT-0700 (US Mountain Standard Time)
I want it to be converted in javascript or in C#
I need the date to be like
2017-09-15 23:47:01
OR perhaps
9/15/2017 11:47:01 PM
I need to also convert it to UTC , not sure if that is easier to do in javascript or in C#
Which type of format is my code even in? "Fri Sep 15 .." ??
For UTC I was seeing code like this
var isoDate = new Date('yourdatehere').toISOString();
( I am doing .net core web api, with Angular 4 / Typescript)
As Keith said, working with dates is really hard in javascript, especially considering very different implementations across the browsers. So I will second their opinion: just use moment.js and leave everything to that library. It is really powerful. Using it you can get any date format you can possibly think of. To get "2017-09-15 23:47:01" all you need is the following (please pay attention that qualifiers are case sensitive!):
var fmt = moment(<your_js_date_if_you_have_it>).format("YYYY-MM-DD HH:mm:ss");
You can find all supported qualifiers here.
Apart from formatting this library also allows you to do a lot of manipulations with the dates, compare them, translate dates from local to UTC time zone and back, etc.

Convert to datetime to local timezone javascript [duplicate]

This question already has answers here:
How to convert Moment.js date to users local timezone?
(5 answers)
Closed 6 years ago.
I am building an app using node.js + postgresql. My postgresql stores dates in the format:
2016-04-01T04:00:00.000Z
When the date is returned to the browser, I want the date to be returned in the timezone of the user. Is there a way I can do this? I found moment.js but I'm not sure if it actually detects a user/browser's timezone for the conversion or not...
Can someone help? Thanks in advance!
If you want suport multitimezone, you should have in db unix timestamps.
Moment js Is really good lib for an time calculation.
Moment js can detect browser timezone.
Of course you always use vanilia like
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getTimezoneOffset

What is the yyyy-mm-ddThh:mm:ss.sssZ date/timezone formatting, and how can I replicate it in JavaScript? [duplicate]

This question already has an answer here:
How to get a zulu timezone representation of the current date
(1 answer)
Closed 7 years ago.
I am trying to replicate this date-time format:
2015-11-05T02:53:04.987Z
I am pretty close using moment().format()
Which gives me:
2015-11-08T14:25:48-08:00
I've tinkered with this a bit but don't understand the formatting well enough. What is happening in the first timestamp offered, and how can I replicate that?
As #RobG points out in the comments, new Date().toISOString() will get you that format.
You mention that you are using moment. If you want to stick with it, moment's utc() and toISOString() will do it too:
var moment = require('moment');
console.log(moment.utc().toISOString()); //2015-11-08T22:32:56.729Z

Categories

Resources