Please enable Javascript for better experience...
Convert JSON date into normal date format
By Rahul Kumar Jha | Jul 12, 2017 | In Tips | Total Views [ 3548 ]
Taged In
(0 Like)

In below section you will find a way to convert JSON date into normal date.

The Problem

I was looking for a way so that I can convert a JSON date into a normal date format. Below code can help you achieving this.

The Solution

Copy below code snippet to your js file. It will definitely work for you.

//Method convert JSON date into normal date
//input parameter as JSON date string, date pattern
function convertJSONDateToStringDate (JSONDate, pattern){
    var dd=String(date.getDate()); if(dd<10){ dd='0'+dd };
    mm=String(date.getMonth()+1); if(mm<10) { mm='0'+mm };
    pattern=pattern.replace(patternDay, dd);
    pattern=pattern.replace(patternMonth, mm);
    pattern=pattern.replace(patternYear, yyyy);
    return pattern;

Calling method

var date = convertJSONDateToStringDate('1516838400000','dd-mm-yyyy');
console.log("Date is:"+ date);

Output: "25-12-2017"

Hope it helps you..

Share this

About the Author

Rahul Kumar Jha
Rahul Kumar Jha
Founder, Developer

Public profile: user/profile/99900001

Has working experience in different phases of Software Development Life Cycle (SDLC) in CMS, Gaming, Health Care and Financial Services domain using Agile pattern. Working experience in Design patterns, ASP.NET, MVC, ANGULAR, ANGULAR JS, Windows application, WCF, ADO.NET, SQL Server and Test Driven Development (TDD) environment with JQuery, JavaScript, N-Unit, Entity Frameworks, LINQ, Code Refactoring and Business Objects Models.

User's Comments

Please SignUp/Login to comment...

Or comment as anonymous...
* Name
* Email ID