0

I am developing MVC application.

I am using Date picker and I would like to set format used by the System.

Please let me know how can I get the date format used by system.

For example if system date is '01/25/2018',How can i get the format as 'mm/dd/yyyy' which is used by system.

I have tried using Date.toLocaleDateString() which is returning the date value.

My requirement is only get the date format used by system.

Please let me know if there is anyway to know the format.

AMDI
  • 895
  • 2
  • 17
  • 40
  • "*Please let me know how can I get the date format used by system*". You can't. There is no standard API to access host system settings for date formatting. – RobG Jan 25 '18 at 11:51

1 Answers1

0

You can get Date simple throgh js like this:

var today = new Date();
var dd = today.getDate();
var mm = today.getMonth()+1; 
var yyyy = today.getFullYear();
 if(dd<10){
  dd='0'+dd;
 } 
 if(mm<10){
  mm='0'+mm;
 } 
var today = dd+'/'+mm+'/'+yyyy;
document.getElementById("systemdate").value = today;
Date: <input id='systemdate'>

or something in short like

var today = new Date() //gives date.
var formatted_date= today.toLocaleDateString(); //your required format
document.getElementById("systemdate").value = formatted_date;
   Date: <input id=systemdate>
Saikat Chakrabortty
  • 2,520
  • 4
  • 22
  • 39
  • 1
    How does that format the date according to "*the date format used by system*"? The two examples above return differently formatted dates for me. – RobG Jan 25 '18 at 11:54
  • @RobG, as per my understanding,he wants something that runs in client system. not in server side. this runs in the browser console. as a pure `js` . so it will get you the system date only. – Saikat Chakrabortty Jan 25 '18 at 11:58
  • By "system" I assume the OP means "host system", so my comment is in regard to client side. – RobG Jan 25 '18 at 12:01