0

I am getting all instead of am or pm
any body help to get am or pm

function display_ct() {
var strcount
var x = new Date()
var x1=x.getMonth() + "/" + x.getDate() + "/" + x.getFullYear();
x1 = x1 + " - " + x.getHours( )+ ":" + x.getMinutes() + ":" + x.getSeconds();
} 
3
Contributors
3
Replies
19
Views
2 Years
Discussion Span
Last Post by ramsiva
1

Here Try this. I hope it works

    <script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
    <script>
        function show_message(msg) {
            $("#msg_div").fadeIn(20);
            $("#msg_div").html(msg);
            $("#msg_div").fadeOut(9999);
        }

        function getval() {
            var currentTime = new Date()
            var hours = currentTime.getHours()
            var minutes = currentTime.getMinutes()

            if (minutes < 10)
                minutes = "0" + minutes;

            var suffix = "AM";
            if (hours >= 12) {
                suffix = "PM";
                hours = hours - 12;
            }
            if (hours == 0) {
                hours = 12;
            }
            var current_time = hours + ":" + minutes + " " + suffix;
            show_message("Current Your System Time is : " + current_time);
        }
    </script>
</head>

<body>
    <div id="msg_div" style="color:green;border: 1px solid green;display:none;"></div>
    <input type="button" value="Get The System Time" onclick="getval();">
1

Here's my go:

    <script>
        function CustomDate()
        {
            this.date = new Date();  
            this.dayPart = this.date.getHours() < 12 ? "AM" : "PM";

            this.toString = function()
            {
                return this.date.getMonth() + "/" + this.date.getDate() + "/" + this.date.getFullYear()
                    + " - " + this.date.getHours( ) + ":" + this.date.getMinutes()
                    + ":" + this.date.getSeconds() + " " + this.dayPart;
            };
        }

        var d = new CustomDate();

        alert(d);
    </script>
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.