Click here to Skip to main content
15,881,413 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi experts,
Is there any way to know the system date is in dd/mm/yyyy or mm/dd/yyyy format
using java script?

thanks in advance
(keerthi Kumar)
Posted
Comments
Bh@gyesh 24-Apr-14 4:44am    
Hi,
You can know the browser culture of client machine. From culture you can know the datetime format.
Specify your requirement so I can help you further..
Keerthi Kumar(Andar) 24-Apr-14 4:48am    
Thanks
Bh@gyesh,
using java script I wanted to display in alert box the system date time format (dd/mm/yyyy or mm/dd/yyyy or yyyy/mm/dd)

If you are usin jQuery then try the following code it will give you system date.
<span id="clientSyatemDate">This is current local Date Time in JQuery></span>
<button type="button" onclick="ClientSystemDate()">GetDate</button>

Script Code:

XML
<script>
       function ClientSystemDate() {
           var todaydate = new Date();
           var localdate = (todaydate.getMonth() + 1) + '/' + todaydate.getDate()  + '/' + todaydate.getFullYear();
           alert($('#clientSyatemDate').text(localdate));
       }
   </script>
 
Share this answer
 
v2
Comments
Keerthi Kumar(Andar) 24-Apr-14 7:22am    
u are taking my question in a wrong way...
imagine in your system's bottom right of the screen is showing date as 04/24/14
u need to give a alert message as mm/dd/yy is that possible??
Snesh Prajapati 24-Apr-14 7:26am    
Thanks. Now I got it. Please wait let me see how to do it.
Snesh Prajapati 24-Apr-14 7:42am    
function ClientSystemDate() {
//var todaydate = new Date();
//var localdate = (todaydate.getMonth() + 1) + '/' + todaydate.getDate() + '/' + todaydate.getFullYear();
//alert($('#clientSyatemDate').text(localdate));

var d = new Date();
var curr_date = d.getDate();
var curr_month = d.getMonth();
var curr_year = d.getFullYear();
curr_date = "dd";
curr_month = "mm";
curr_year = "yyyy";

alert(curr_date + "/" + curr_month + "/" + curr_year);

}

the above code will return date format like dd/mm/yyyy...Still I am looking for appropriate way to achieve the same. For time being you can use..modify accordingly if required
Keerthi Kumar(Andar) 25-Apr-14 1:03am    
i have got a solution...but problem is that if i host the project in IIS its not working.
Can you please help me to solve this issue.??
Snesh Prajapati 25-Apr-14 1:34am    
Here as a solution I am seeing that you have posted solution. Did you solve your problem?
XML
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="javascript.WebForm1" %>
<%@ Import Namespace="System.Globalization" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head >
<script type="text/javascript">
    function show() {
        var cultureInfo = "<%= CultureInfo.CurrentCulture.DateTimeFormat.ShortDatePattern.ToString() %>";
        alert(cultureInfo);
    }
</script>
</head>
<body onload="show()">
    <form id="form1" runat="server">
    <div>
    <asp:Label ID="lblDate" runat="server" ></asp:Label>
    </div>
    </form>
</body>
</html>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900