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();
} 

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();">

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>

Thanx For giving Valuable Coding for me

Regards,
Ramu

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.