Click here to Skip to main content
15,886,710 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi experts,

I need a java script which helps me to get the client
Systems date format can any one please help me to solve this issue??

thanks in advance
(Keerthi Kumar)
Posted
Updated 12-Jul-19 8:33am
Comments
Bh@gyesh 24-Apr-14 6:26am    
Hi,
You can get client browser locale (language). It ultimately give u date format for client machine.

Please specify your requirement, so I can assist you further...

 
Share this answer
 
Comments
Keerthi Kumar(Andar) 24-Apr-14 2:20am    
Sorry Mukesh Ghosh , there is no such explanation.
that i can solve this problem
Mukesh Ghosh 24-Apr-14 2:26am    
you may use toLocaleDateString() of Date object to get a string of a specific date (like 12/13/2014) and then analyze the string to decide what was the original formatting string...
Keerthi Kumar(Andar) 24-Apr-14 6:42am    
thanks Mukesh Ghoshi,
i think u hav not understood my quetion. I wanted to display the client systems date time format(means dd/mm/yyyy)
as a alert message using java script. Is there any way to solve this problm??
Try this

XML
<script type="text/javascript"><!--
var date = new Date();
var d  = date.getDate();
var day = (d < 10) ? '0' + d : d;
var m = date.getMonth() + 1;
var month = (m < 10) ? '0' + m : m;
var yy = date.getYear();
var year = (yy < 1000) ? yy + 1900 : yy;

alert(day + "/" + month + "/" + year);
 //--></script>
 
Share this answer
 
Comments
Keerthi Kumar(Andar) 24-Apr-14 7:06am    
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??
Mukesh Ghosh 24-Apr-14 7:11am    
Each time you are changing your requirement. Please mention your needs in proper way
without making any confusion, we are all here to help you but requirement shouldn't make other to be puzzled.
Keerthi Kumar(Andar) 24-Apr-14 7:22am    
sorry Mukesh,
I have not changed my requirement . bcoz of some poor english u took my quetion in a wrong way.
nw r u clear wid the pblm??
Keerthi Kumar(Andar) 25-Apr-14 1:02am    
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.??
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
 
Hi, I made a function to determine the client date format. The function determine
the date format separator, and also determine the 1st, 2nd and third part of
the date format.

Java
getDateFormat(){
        // initialize date value "31st January 2019"
        var my_date = new Date(2019,0,31);
        console.log(my_date.toLocaleDateString());
        // Initialize variables
        var separator="";
        var first="";
        var second="";
        var third="";
        var date_parts = [];

        // get separator : "-", "/" or " ", format based on toLocaleDateString function        
        if (my_date.toLocaleDateString().split("-").length==3){
            separator = " - ";
            date_parts = my_date.toLocaleDateString().split("-");
        } 
        if (my_date.toLocaleDateString().split("/").length == 3) {
            separator = " / ";
            date_parts = my_date.toLocaleDateString().split("/");
        } 
        if (my_date.toLocaleDateString().split(" ").length == 3) {
            separator = " ";
            date_parts = my_date.toLocaleDateString().split(" ");
        } 

        // get first part        
        if (date_parts[0]==2019){
            first ="yyyy";
        } else if (date_parts[0] == 31){
            first = "dd";
        } else{
            if (date_parts[0].length<=2){
                first ="mm";
            }
            else{
                first="mmm";
            }
        }

        // get second part        
        if (date_parts[1] == 2019) {
            second = "yyyy";
        } else if (date_parts[1] == 31) {
            second = "dd";
        } else {
            if (date_parts[1].length <= 2) {
                second = "mm";
            }
            else {
                second = "mmm";
            }
        }

        // get third part        
        if (date_parts[2] == 2019) {
            third = "yyyy";
        } else if (date_parts[2] == 31) {
            third = "dd";
        } else {
            if (date_parts[2].length <= 2) {
                third = "mm";
            }
            else {
                third = "mmm";
            }
        }

        // assembly
        var format = first + separator + second + separator + third;
        console.log(format);
        return format;
    }
 
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