Javascript Datetime Conversion
Published in
1 min readJun 4, 2021
Hi Guys, today I want to explain time problems as I am known. When you use javascript on your front end, you will use the javascript time property.
In my case, I used
- angular.js on the front end
- .net 5 on the back end
- SQL server 12.0 sp2 on db
As you know SQL Server accepts DateTime format like ‘yyyy-mm-dd HH:mm:ss’, you have 2 options on your backend to carry date filter one is DateTime format other is a string, I used DateTime format
let fakeDate = new Date()
fakeDate will look like this
Fri Jun 04 2021 17:42:26 GMT+0300 (GMT+03:00)
My solution is
let d = fakeDatelet date = d.getFullYear().toString() + "-" + ((d.getMonth() + 1).toString().length == 2 ? (d.getMonth() + 1).toString() : "0" + (d.getMonth() + 1).toString()) + "-" + (d.getDate().toString().length == 2 ? d.getDate().toString() : "0" + d.getDate().toString())let time = d.toLocaleString('en-US', { timeZone: 'Europe/Istanbul' }).split(',')[1];filterData = date + time