Click here to Skip to main content
15,907,000 members
Please Sign up or sign in to vote.
3.67/5 (2 votes)
See more:
Hi
I need to send the date format of the client system to the db when user request for time .how can i get current system format in string eg "MM/DD/yy HH:MI' etc
Posted
Comments
Maciej Los 31-Jul-13 6:25am    
Why to collect client system date format?
Joezer BH 1-Aug-13 2:21am    
I am not sure why he needs it, but it's a good question and 6 out of 7 solutions below missed the question altogether...
Maciej Los 1-Aug-13 2:27am    
Thank you. It's good to know that here are people who thinking same way ;)

Cheers!

 
Share this answer
 
DateTime.Now.ToString("dd/MM/yyyy HH:mm");
 
Share this answer
 
CultureInfo culture = CultureInfo.CreateSpecificCulture(Request.UserLanguages[0]);
string dd = culture.DateTimeFormat.ShortDatePattern;
 
Share this answer
 
Hi,
Try this one....
GetFormattedDate('dd/mm/yyyy')

C#
public static string GetFormattedDate(string strDate)
        {
            //string ci = CultureInfo.CurrentCulture.ToString();
            string[] DateArray = strDate.Split('/');
            string strResultDate = "";

            if (getDateRangeSetting() == "0") //mm/dd/yyy
            {
                strResultDate = DateArray[1].ToString() + "/" + DateArray[0].ToString() + "/" + DateArray[2].ToString();

            }
            else
            {
                /* dd/mm/yyyy */
                strResultDate = strDate.ToString();
            }
            return strResultDate;

        }

public static string getDateRangeSetting()
        {
            string strRetNumber = "1";
            string srDatePattern = System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.ShortDatePattern.ToString();
            switch (srDatePattern)
            {
                case "M/d/yyyy": strRetNumber = "0";
                    break;
                case "d/M/yyyy": strRetNumber = "1";
                    break;
            }

            return strRetNumber;
        }
 
Share this answer
 
v4
You can use Date object of javascript.For demonstration.

JavaScript
var date= new Date();
    var month = (date.getMonth())+1;
    var day = date.getDay();
    var year = date.getYear();
    var hour = date.getHours();
    var minute = date.getMinutes();
    var currDateFormat = month + "/" + day + "/" + year + " " + hour + ":" + minute;
    window.document.write(currDateFormat);


Then make an ajax call to server,sending your formatted date to server.Use Jquery ajax construct as below.
JavaScript
$.ajax({
            url: "Your url",
            type: "post",
            data: currDateFormat,
            success: function (response) {            
}
});

In above code you can recollect the status of your data base operation from any server side coding in success function code block of ajax.Here in above code use 'response' to achieve it.Hope this will help you.
 
Share this answer
 
v3
You don't.

Instead, you transfer data between server and client in a way that you know.

Then, for displaying data on the client side, use the client's standard displaying format. You don't need to know what that format is, just use the standard DateTime.ToString()[^] method.
 
Share this answer
 
XML
<html>
<body>
<h4>It is now
<script type="text/javascript">
<!--
var currentTime = new Date()
var hours = currentTime.getHours()
var minutes = currentTime.getMinutes()
if (minutes < 10){
minutes = "0" + minutes
}
document.write(hours + ":" + minutes + " ")
if(hours > 11){
document.write("PM")
} else {
document.write("AM")
}
//-->
</script>
</h4>
</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