Click here to Skip to main content
15,887,267 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
date present in database 2020-10-16 09:14:31.000 is coming NaN-undefined-NaN NaN:NaN:NaN AM in internet explorer while retriving in knockout js but it coming properly in google chrome kindly help for same


What I have tried:

JavaScript
self.LastSaveDate = ko.observable();
            if (item.LastSaveDate != '' && item.LastSaveDate != null && item.LastSaveDate != 'undefined') {


                self.LastSaveDate(formatDate(new Date(item.LastSaveDate + 'UTC').toString()));
            } else {
                self.LastSaveDate('');
            }

JavaScript
function formatDate(dt) {
    var current_datetime = new Date(dt);
    var hours = current_datetime.getHours() > 12 ? current_datetime.getHours() - 12 : current_datetime.getHours();
    var am_pm = current_datetime.getHours() >= 12 ? "PM" : "AM";
    hours = hours < 10 ? "0" + hours : hours;
    var minutes = current_datetime.getMinutes() < 10 ? "0" + current_datetime.getMinutes() : current_datetime.getMinutes();
    var seconds = current_datetime.getSeconds() < 10 ? "0" + current_datetime.getSeconds() : current_datetime.getSeconds();
    time = hours + ":" + minutes + ":" + seconds + " " + am_pm;
    var formatted_date = current_datetime.getDate() + "-" + months[current_datetime.getMonth()] + "-" + current_datetime.getFullYear() + ' ' + time;
    return formatted_date;
    
}
var months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
Posted
Updated 18-Oct-20 19:36pm
v2

1 solution

Quote:
Date present in database 2020-10-16 09:14:31.000 is coming nan-undefined-nan nan:nan:nan AM in internet explorer while retriving in knockout js but it coming properly in Google chrome

IE start to be a little dated, even MS don't use it anymore.
You may need different code for both navigators.
To understand what is going on, only 1 solution, the debugger or debugging techniques.
Navigating the F12 Developer Tools Interface (Internet Explorer) | Microsoft Docs[^]

Your code do not behave the way you expect, or you don't understand why !

There is an almost universal solution: Run your code on debugger step by step, inspect variables.
The debugger is here to show you what your code is doing and your task is to compare with what it should do.
There is no magic in the debugger, it don't know what your code is supposed to do, it don't find bugs, it just help you to by showing you what is going on. When the code don't do what is expected, you are close to a bug.
To see what your code is doing: Just set a breakpoint and see your code performing, the debugger allow you to execute lines 1 by 1 and to inspect variables as it execute.

Debugger - Wikipedia, the free encyclopedia[^]

Mastering Debugging in Visual Studio 2010 - A Beginner's Guide[^]
Basic Debugging with Visual Studio 2010 - YouTube[^]

JavaScript Debugging[^]
Chrome DevTools  |  Web  |  Google Developers[^]

The debugger is here to only show you what your code is doing and your task is to compare with what it should do.
 
Share this answer
 

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