Date in Javascript vs C#

By Sky Lee | 20 Mar 2020 • 1 min read

Examples

Date usage in Javascript and C# are very similar. Here is the comparison of the common methods that I use frequently.

Method Javascript C#
Date to String date.toISOString().split("T")[0] date.ToString("yyyy-MM-dd");
Input: Thu Jun 11 2020 00:00:00 GMT+0800
Output: 2020-06-11
String to Date new Date("2019-06-11") new DateTime(2019, 6, 11);
Input: 2020-06-11
Output: Thu Jun 11 2020 00:00:00 GMT+0800
Current Date Time (Local) new Date() DateTime.Now;
Output: Thu Jun 11 2020 00:00:00 GMT+0800
Current Date Time (UTC) new Date(new Date().toUTCString()) DateTime.UtcNow;
Output: 2020-06-11