Convert Json Date String To Date Format In jQuery

15:51

Introduction

In this post I want to show, how to Convert json date to date format in jQuery.

Problem

Suppose you want to convert '/Date(1448583916000)/' to datetime format in jquery

Solution

Follow this function:
    function dateTimeFormat(dateTimeValue) 
    {
        var dt = new Date(parseInt(dateTimeValue.replace(/(^.*\()|([+-].*$)/g, '')));
        var dateTimeFormat = dt.getDate() + "/" + (dt.getMonth() + 1) + "/" + dt.getFullYear();
        return dateTimeFormat;
    }
Now if we want to convert '/Date(1448583916000)/' to 'dd/mm/yyyy' format.

Out Put

27/11/2015

If You Want Time

    function dateTimeFormat(dateTimeValue) 
    {
        var dt = new Date(parseInt(dateTimeValue.replace(/(^.*\()|([+-].*$)/g, '')));
        var dateTimeFormat = dt.getDate() + "/" + (dt.getMonth() + 1) + "/" + dt.getFullYear() + ' ' + dt.getHours() + ":" + dt.getMinutes() + ":" + dt.getSeconds();
        return dateTimeFormat;
    }

Out Put

27/11/2015 5:55:16

Conclusion

Guys I show Convert json date to date format in jQuery. If you facing any other problem please leave a comment.

You Might Also Like

0 comments