Converting DateTimeOffset string value to Date object in javascript

convert utc to local time javascript
moment js
javascript date without timezone
javascript get timezone offset for specific timezone
failed to convert parameter value from a datetimeoffset to a datetime
javascript date timezone
javascript date to c# datetimeoffset
javascript convert date format

I'm using ASP.NET and I have the following string:

2018-12-04T13:53:42.6785734+07:00

I want to convert the string to Date object and format the output string.

My goal: 04/12/2018 13:53:42

I've tried this way but it logged with the wrong result:

var dt = new Date('2018-12-04T13:53:42.6785734+07:00'); 

var day = dt.getDay(),
    month = dt.getMonth(),
    year = dt.getFullYear(),
    hours = dt.getHours(),
    minutes = dt.getMinutes(),
    seconds = dt.getSeconds();
    
// 2/11/2018 13:53:42    
console.log(day + '/' + month + '/' + year + ' ' + hours + ':' + minutes + ':' + seconds);

var dt = new Date('2018-12-04T13:53:42.6785734+07:00'); 

var day = dt.getDate(),
month = dt.getMonth(),
year = dt.getFullYear(),
hours = dt.getHours(),
minutes = dt.getMinutes(),
seconds = dt.getSeconds();

// 2/11/2018 13:53:42    
console.log(day + '/' + (month + 1) + '/' + year + ' ' + hours + ':' + minutes + ':' + seconds);

How can I convert string to datetime with format specification in , How can I convert a string to a date time object in javascript by specifying a format string? I am looking for something like: var dateTime = convertToDateTime​("  An object that is equivalent to the date and time that is contained in input as specified by formatProvider and styles. Parse (String, IFormatProvider, DateTimeStyles) Converts the specified string representation of a date and time to its DateTimeOffset equivalent using the specified culture-specific format information and formatting style.


Would it be acceptable to just manipulate the original string directly without converting to a date object like so? I can really tell what the test cases would be but assuming that the hour number is the same length (04,12) I think the following code should work.

let dt = '2018-12-04T13:53:42.6785734+07:00';
let  dArr = dt.substr(0,10).split('-');
let year = dArr[0];
let month = dArr[1];
let day = dArr[2];
let time = dt.substr(11,8);

let str = month+'/'+day+'/'+year+' '+time;

console.log(str)

JavaScript getTimezoneOffset() Method, var d = new Date(); var n = d. Note: The returned value is not a constant, because of the practice of using Daylight Saving Time. Date.getTimezoneOffset​()  The toString () method converts a Date object to a string. Note: This method is automatically called by JavaScript whenever a Date object needs to be displayed as a string.


The following are arrays starting at 0 getDay() Get the weekday as a number (0-6) getDate() Get the day as a number (1-31) getMonth() Get the month as a number (0-11)

var dt = new Date("2018-12-04T13:53:42.6785734+07:00"); 

var day = returnDay(),
month = returnMonth(),
year = dt.getFullYear(),
hours = dt.getHours(),
minutes = dt.getMinutes(),
seconds = dt.getSeconds(),


function returnDay(){
  var d = (dt.getDate() < 10) ? "0" + (dt.getDate()): dt.getDate();
  return d;
}

function returnMonth(){
  var m = (dt.getMonth() + 1 < 10) ? "0" + (dt.getMonth()+ 1):dt.getMonth()+ 1;
  return m;
}

//04/12/2018 8:53:42
console.log(day + '/' + month + '/' + year + ' ' + hours + ':' + minutes + ':' + seconds);

see for more info: https://www.w3schools.com/js/js_date_methods.asp

JavaScript toUTCString() Method, The toUTCString() method converts a Date object to a string, according to universal time. Tip: The Universal Coordinated Time (UTC) is the time set by the World  I'm wondering on the correct way to convert a string date in a non-ISO format to a different offset/timezone. I am currently given 3 values: the date in format MM/DD/YYYY (23/11/2016) the time in 24h format (23:13) timezone offset (-07:00) I would like to convert said date to the user's timezone.


Slice it, I have used jQuery in the example because I have used in in another project and this code was just a part of a component, but it should not matter much

var getTimeOnly = new Date().getTime();
var fullDate = new Date($.now()).toString();
var datePartialTime = fullDate.slice(16, 25);
var datePartialDate = fullDate.slice(0, 16);



$('a').html( "on " + datePartialDate + 'at ' + datePartialTime);

Link to pen

https://codepen.io/damPop/pen/zMzBGN

JS.JSON.stringify converts DateTimeOffset to UTC format · Issue , Note: Actually at runtime Fable just checks if the value is a JS Date but ToString("​O") works both with DateTime and DateTimeOffset so it shouldn't  The implicit conversion operator, which allows you to assign a DateTime value to a DateTimeOffset object. For UTC and local DateTime values, the Offset property of the resulting DateTimeOffset value accurately reflects the UTC or local time zone offset. For example, the following code converts a UTC time to its equivalent DateTimeOffset value.


How To Work with Date and Time in JavaScript using Date Objects , JavaScript comes with the built in Date object and related methods. How To Convert Data Types in JavaScript Looking at the output, we have a date string containing the following: JavaScript, however, understands the date based on a timestamp derived from Unix time, which is a value consisting of  I have a dictionary of string and object, for integer part I can use Convert.ToInt32() , but for DateTimeOffset, I can't seem to find any (there's Convert.ToDateTime() but I'm afraid the Offset part would be trimmed), I tried searching the stackoverflow and web but nothing can be used.


C#: how to convert a String to DateTime ignoring TimeZone – Expert , To convert a String into a DateTime we can use the DateTime.Parse method. Parse("2018-10-02 11:25:27.860"); Now the myDt contains a date with 02/10/​2018 11:25:27 value (on italian format). But if our If we want to ignore the TimeZone, we can use the DateTimeOffset. In "TypeScript JavaScript"  The Date object is used to work with dates and times. Date objects are created with new Date (). There are four ways of instantiating a date: var d = new Date ();


DateTime.SpecifyKind(DateTime, DateTimeKind) Method (System , Creates a new DateTime object that has the same number of ticks as the specified public static DateTime SpecifyKind (DateTime value, DateTimeKind kind); time, and the DateTime // structure converted to universal time. public static string  The ToString () method returns the string representation of the date and time in the calendar used by the current culture. If the value of the current DateTimeOffset instance is earlier than MinSupportedDateTime or later than MaxSupportedDateTime, the method throws an ArgumentOutOfRangeException. The following example provides an illustration.