Click here to Skip to main content
15,924,318 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
I am using WCf rest service code in asp.net. I have convert the list of objects in json format.so datetime formate are also converted in json "ModifiedDate":"\/Date(1467094060213+0530)\/"). I want to display DateTime in Basic With AM/PM also.I sucessfully converted json DateTime formate to Basi DateTime format in jquery. My out is

Tue Jun 28 2016 11:37:40 GMT+0530 (India Standard Time)


I want to need output of - jun 28 2016 11:37 AM

below i added my code please help......

What I have tried:

JavaScript
<script type="text/javascript">
        $(document).ready(function () {
            debugger;      
                $.getJSON('http://localhost:33804/NewsRestService.svc/NewsById/0', function (data) {
                    var out1 = "";
                    var i;
                    for (i = 0; i < data.NewsByIdResult.length; i++) {
var dateString = data.NewsByIdResult[i].CreatedDate.substr(6);
                        var currentTime = new Date(parseInt(dateString));
                        var month = currentTime.getMonth() + 1;
                        var day = currentTime.getDate();
                        var year = currentTime.getFullYear();                       
                        var date = currentTime;
out1 +=date
}
document.getElementById("newshref").innerHTML = out1;
                });
            });
Posted
v3

 
Share this answer
 
Comments
Karthik_Mahalingam 29-Jun-16 3:19am    
5! almost similar :)
Thanks man :)
Thiyagu Arockiasamy 29-Jun-16 5:13am    
Thanks a lot . Its Work Fine for me.
Most welcome buddy. :)
try this

JavaScript
function getMyFormatDate(date) {
           var months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
           var d = date;
           var hours = d.getHours();
           var ampm = hours >= 12 ? 'PM' : 'AM';
           return months[d.getMonth()] + ' ' + d.getDate() + " " + d.getFullYear() + ' ' + hours + ':' + d.getMinutes() + ' ' + ampm;
       }

       var dateObj = new Date();
       var dateFormat = getMyFormatDate(dateObj); // Jun 29 2016 12:40 AM



demo : Edit fiddle - JSFiddle[^]
 
Share this answer
 
v2
Comments
Karthik_Mahalingam 29-Jun-16 5:31am    
Thanks Tadit :)
Thiyagu Arockiasamy 29-Jun-16 6:35am    
Thanks a lot :-)
 
Share this answer
 
Comments
Thiyagu Arockiasamy 29-Jun-16 9:21am    
Thanks a lot Madhu....
I have guess cuz I dont so know javascript or jquery syntax.
But can you try code below,bro.

JavaScript
<script type="text/javascript">
var dateString = data.NewsByIdResult[i].ModifiedDate.substr(6);
var currentTime = new Date(parseInt(dateString));

var monthNumber = currentTime.getMonth() + 1;
var day = currentTime.getDate();
var year = currentTime.getFullYear();

var months = [ "Jan", "Feb", "Mar", "Apr", "May", "Jun", 
               "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" ];

var monthName = months[monthNumber];

var ampm = (currentTime.getHours() >= 12) ? 'PM' : 'AM';
var times = (currentTime.getHours() >= 12) ? currentTime.getHours()-12 + ':' + currentTime.getMinutes() + ' ' + ampm : currentTime.getHours() + ':' + currentTime.getMinutes() + ' ' + ampm;

var yourWantOutput = monthName + ' ' + day + ' ' + year + '  ' + times;

alert(yourWantOutput);

</script>
 
Share this answer
 
v3
Comments
Thiyagu Arockiasamy 29-Jun-16 8:56am    
Thanks for your help bro . thanks a lot
var num = 1513923197424;
var date = new Date(parseInt(num.toString()));
alert(date);
 
Share this answer
 
Comments
Richard Deeming 22-Dec-17 12:37pm    
Asked, answered, and solved EIGHTEEN MONTHS AGO.

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