Javascript date object, getDate(), getMonth() and getFullYear() of date object in IE and SafariLength of a JavaScript objectWhat is the most efficient way to deep clone an object in JavaScript?How do I remove a property from a JavaScript object?How do I check if an array includes an object in JavaScript?Compare two dates with JavaScriptHow do I correctly clone a JavaScript object?Checking if a key exists in a JavaScript object?Detecting an “invalid date” Date instance in JavaScriptHow do I get the current date in JavaScript?How to format a JavaScript date

Working in the USA for living expenses only; allowed on VWP?

Do adult Russians normally hand-write Cyrillic as cursive or as block letters?

Does the growth of home value benefit from compound interest?

Building a road to escape Earth's gravity by making a pyramid on Antartica

What can plausibly explain many of my very long and low-tech bridges?

Removing applications from Show Applications without uninstalling

Is it possible for people to live in the eye of a permanent hypercane?

Accidentally renamed tar.gz file to a non tar.gz file, will my file be messed up

Why don't B747s start takeoffs with full throttle?

Word for a small burst of laughter that can't be held back

Short story written from alien perspective with this line: "It's too bright to look at, so they don't"

What's the logic behind the the organization of Hamburg's bus transport into "rings"?

X-shaped crossword

Can a 2nd-level sorcerer use sorcery points to create a 2nd-level spell slot?

How can I instantiate a lambda closure type in C++11/14?

Adding two lambda-functions in C++

Java guess the number

What happens to foam insulation board after you pour concrete slab?

Is there any word or phrase for negative bearing?

Why did a party with more votes get fewer seats in the 2019 European Parliament election in Denmark?

Is it legal in the UK for politicians to lie to the public for political gain?

What is the advantage of carrying a tripod and ND-filters when you could use image stacking instead?

How to decline physical affection from a child whose parents are pressuring them?

Are there cubesats in GEO?



Javascript date object, getDate(), getMonth() and getFullYear() of date object in IE and Safari


Length of a JavaScript objectWhat is the most efficient way to deep clone an object in JavaScript?How do I remove a property from a JavaScript object?How do I check if an array includes an object in JavaScript?Compare two dates with JavaScriptHow do I correctly clone a JavaScript object?Checking if a key exists in a JavaScript object?Detecting an “invalid date” Date instance in JavaScriptHow do I get the current date in JavaScript?How to format a JavaScript date






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















I use this function in my Javascript code in order to format dateTime object into string and this function works fine for Firefox and Chrome but not for IE and Safari.
Does anyone know what to do in order to make this also work with Safari and IE?



date Object looks like this in Chrome: Mon Mar 25 2019 00:00:00 GMT+0100 (CET)






function formatDateTimeToString(date) 
var dd = (date.getDate() < 10 ? '0' : '') + date.getDate();
var MM = ((date.getMonth() + 1) < 10 ? '0' : '') + (date.getMonth() + 1);
var yyyy = date.getFullYear();
var hours = (date.getHours() < 10 ? '0' : '') + date.getHours();
var minutes = (date.getMinutes() < 10 ? '0' : '') + date.getMinutes();
return (dd + "." + MM + "." + yyyy + ' ' + hours + ':' + minutes);


console.log(formatDateTimeToString(new Date()));












share|improve this question
























  • what about using moment.js

    – Microsmsm
    Mar 24 at 14:25











  • what are you getting in safari and IE

    – FedeSc
    Mar 24 at 14:27











  • I get NaN.NaN. ... in Safari and IE

    – quma
    Mar 24 at 14:29











  • How can moment solve this issue?

    – quma
    Mar 24 at 14:30






  • 1





    "date Object looks like this…" Date objects are just a number (a time value) and some methods, the default string representation was, until recently, implementation dependent. As Trincot says, check that your issue isn't with parsing as there is nothing in the OP that should differer between implementations.

    – RobG
    Mar 24 at 23:14


















0















I use this function in my Javascript code in order to format dateTime object into string and this function works fine for Firefox and Chrome but not for IE and Safari.
Does anyone know what to do in order to make this also work with Safari and IE?



date Object looks like this in Chrome: Mon Mar 25 2019 00:00:00 GMT+0100 (CET)






function formatDateTimeToString(date) 
var dd = (date.getDate() < 10 ? '0' : '') + date.getDate();
var MM = ((date.getMonth() + 1) < 10 ? '0' : '') + (date.getMonth() + 1);
var yyyy = date.getFullYear();
var hours = (date.getHours() < 10 ? '0' : '') + date.getHours();
var minutes = (date.getMinutes() < 10 ? '0' : '') + date.getMinutes();
return (dd + "." + MM + "." + yyyy + ' ' + hours + ':' + minutes);


console.log(formatDateTimeToString(new Date()));












share|improve this question
























  • what about using moment.js

    – Microsmsm
    Mar 24 at 14:25











  • what are you getting in safari and IE

    – FedeSc
    Mar 24 at 14:27











  • I get NaN.NaN. ... in Safari and IE

    – quma
    Mar 24 at 14:29











  • How can moment solve this issue?

    – quma
    Mar 24 at 14:30






  • 1





    "date Object looks like this…" Date objects are just a number (a time value) and some methods, the default string representation was, until recently, implementation dependent. As Trincot says, check that your issue isn't with parsing as there is nothing in the OP that should differer between implementations.

    – RobG
    Mar 24 at 23:14














0












0








0








I use this function in my Javascript code in order to format dateTime object into string and this function works fine for Firefox and Chrome but not for IE and Safari.
Does anyone know what to do in order to make this also work with Safari and IE?



date Object looks like this in Chrome: Mon Mar 25 2019 00:00:00 GMT+0100 (CET)






function formatDateTimeToString(date) 
var dd = (date.getDate() < 10 ? '0' : '') + date.getDate();
var MM = ((date.getMonth() + 1) < 10 ? '0' : '') + (date.getMonth() + 1);
var yyyy = date.getFullYear();
var hours = (date.getHours() < 10 ? '0' : '') + date.getHours();
var minutes = (date.getMinutes() < 10 ? '0' : '') + date.getMinutes();
return (dd + "." + MM + "." + yyyy + ' ' + hours + ':' + minutes);


console.log(formatDateTimeToString(new Date()));












share|improve this question
















I use this function in my Javascript code in order to format dateTime object into string and this function works fine for Firefox and Chrome but not for IE and Safari.
Does anyone know what to do in order to make this also work with Safari and IE?



date Object looks like this in Chrome: Mon Mar 25 2019 00:00:00 GMT+0100 (CET)






function formatDateTimeToString(date) 
var dd = (date.getDate() < 10 ? '0' : '') + date.getDate();
var MM = ((date.getMonth() + 1) < 10 ? '0' : '') + (date.getMonth() + 1);
var yyyy = date.getFullYear();
var hours = (date.getHours() < 10 ? '0' : '') + date.getHours();
var minutes = (date.getMinutes() < 10 ? '0' : '') + date.getMinutes();
return (dd + "." + MM + "." + yyyy + ' ' + hours + ':' + minutes);


console.log(formatDateTimeToString(new Date()));








function formatDateTimeToString(date) 
var dd = (date.getDate() < 10 ? '0' : '') + date.getDate();
var MM = ((date.getMonth() + 1) < 10 ? '0' : '') + (date.getMonth() + 1);
var yyyy = date.getFullYear();
var hours = (date.getHours() < 10 ? '0' : '') + date.getHours();
var minutes = (date.getMinutes() < 10 ? '0' : '') + date.getMinutes();
return (dd + "." + MM + "." + yyyy + ' ' + hours + ':' + minutes);


console.log(formatDateTimeToString(new Date()));





function formatDateTimeToString(date) 
var dd = (date.getDate() < 10 ? '0' : '') + date.getDate();
var MM = ((date.getMonth() + 1) < 10 ? '0' : '') + (date.getMonth() + 1);
var yyyy = date.getFullYear();
var hours = (date.getHours() < 10 ? '0' : '') + date.getHours();
var minutes = (date.getMinutes() < 10 ? '0' : '') + date.getMinutes();
return (dd + "." + MM + "." + yyyy + ' ' + hours + ':' + minutes);


console.log(formatDateTimeToString(new Date()));






javascript date






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 24 at 23:13









RobG

101k19113151




101k19113151










asked Mar 24 at 14:22









qumaquma

83983786




83983786












  • what about using moment.js

    – Microsmsm
    Mar 24 at 14:25











  • what are you getting in safari and IE

    – FedeSc
    Mar 24 at 14:27











  • I get NaN.NaN. ... in Safari and IE

    – quma
    Mar 24 at 14:29











  • How can moment solve this issue?

    – quma
    Mar 24 at 14:30






  • 1





    "date Object looks like this…" Date objects are just a number (a time value) and some methods, the default string representation was, until recently, implementation dependent. As Trincot says, check that your issue isn't with parsing as there is nothing in the OP that should differer between implementations.

    – RobG
    Mar 24 at 23:14


















  • what about using moment.js

    – Microsmsm
    Mar 24 at 14:25











  • what are you getting in safari and IE

    – FedeSc
    Mar 24 at 14:27











  • I get NaN.NaN. ... in Safari and IE

    – quma
    Mar 24 at 14:29











  • How can moment solve this issue?

    – quma
    Mar 24 at 14:30






  • 1





    "date Object looks like this…" Date objects are just a number (a time value) and some methods, the default string representation was, until recently, implementation dependent. As Trincot says, check that your issue isn't with parsing as there is nothing in the OP that should differer between implementations.

    – RobG
    Mar 24 at 23:14

















what about using moment.js

– Microsmsm
Mar 24 at 14:25





what about using moment.js

– Microsmsm
Mar 24 at 14:25













what are you getting in safari and IE

– FedeSc
Mar 24 at 14:27





what are you getting in safari and IE

– FedeSc
Mar 24 at 14:27













I get NaN.NaN. ... in Safari and IE

– quma
Mar 24 at 14:29





I get NaN.NaN. ... in Safari and IE

– quma
Mar 24 at 14:29













How can moment solve this issue?

– quma
Mar 24 at 14:30





How can moment solve this issue?

– quma
Mar 24 at 14:30




1




1





"date Object looks like this…" Date objects are just a number (a time value) and some methods, the default string representation was, until recently, implementation dependent. As Trincot says, check that your issue isn't with parsing as there is nothing in the OP that should differer between implementations.

– RobG
Mar 24 at 23:14






"date Object looks like this…" Date objects are just a number (a time value) and some methods, the default string representation was, until recently, implementation dependent. As Trincot says, check that your issue isn't with parsing as there is nothing in the OP that should differer between implementations.

– RobG
Mar 24 at 23:14













1 Answer
1






active

oldest

votes


















0














If the date object for Safari is generated the same way as it is done for Chrome, then at least in my old version of Safari the code runs successfully, as follows:



function formatDateTimeToString(date) 
var dd = (date.getDate() < 10 ? '0' : '') + date.getDate();
var MM = ((date.getMonth() + 1) < 10 ? '0' : '') + (date.getMonth() + 1);
var yyyy = date.getFullYear();
var hours = (date.getHours() < 10 ? '0' : '') + date.getHours();
var minutes = (date.getMinutes() < 10 ? '0' : '') + date.getMinutes();
return (dd + "." + MM + "." + yyyy + ' ' + hours + ':' + minutes);


var d = document;
d.w = d.writeln;
var date = new Date("Mon Mar 25 2019 00:00:00 GMT+0100 (CET)");

/* this works */
d.w( formatDateTimeToString(date)+"<BR>");

// output:
// 24.03.2019 16:00


You may get NaN as a result in Safari if you attempt to instantiate a Date object with a string containing hyphens, as follows:



var d = document;
d.w = d.writeln;

date = new Date("2019-03-24");
/* returns NaN */
d.w( formatDateTimeToString(date)+"<BR>");

date = new Date("03-24-2019");
/* this fails with NaN*/
d.w( formatDateTimeToString(date)+"<BR>");





share|improve this answer

























  • This seems to be off topic. While the issue may be how the OP is generating their Date, the question starts with a Date object so you/we really don't know yet. This should just be a comment, there are many, many questions already about parsing.

    – RobG
    Mar 24 at 23:17











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55324774%2fjavascript-date-object-getdate-getmonth-and-getfullyear-of-date-object-i%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














If the date object for Safari is generated the same way as it is done for Chrome, then at least in my old version of Safari the code runs successfully, as follows:



function formatDateTimeToString(date) 
var dd = (date.getDate() < 10 ? '0' : '') + date.getDate();
var MM = ((date.getMonth() + 1) < 10 ? '0' : '') + (date.getMonth() + 1);
var yyyy = date.getFullYear();
var hours = (date.getHours() < 10 ? '0' : '') + date.getHours();
var minutes = (date.getMinutes() < 10 ? '0' : '') + date.getMinutes();
return (dd + "." + MM + "." + yyyy + ' ' + hours + ':' + minutes);


var d = document;
d.w = d.writeln;
var date = new Date("Mon Mar 25 2019 00:00:00 GMT+0100 (CET)");

/* this works */
d.w( formatDateTimeToString(date)+"<BR>");

// output:
// 24.03.2019 16:00


You may get NaN as a result in Safari if you attempt to instantiate a Date object with a string containing hyphens, as follows:



var d = document;
d.w = d.writeln;

date = new Date("2019-03-24");
/* returns NaN */
d.w( formatDateTimeToString(date)+"<BR>");

date = new Date("03-24-2019");
/* this fails with NaN*/
d.w( formatDateTimeToString(date)+"<BR>");





share|improve this answer

























  • This seems to be off topic. While the issue may be how the OP is generating their Date, the question starts with a Date object so you/we really don't know yet. This should just be a comment, there are many, many questions already about parsing.

    – RobG
    Mar 24 at 23:17















0














If the date object for Safari is generated the same way as it is done for Chrome, then at least in my old version of Safari the code runs successfully, as follows:



function formatDateTimeToString(date) 
var dd = (date.getDate() < 10 ? '0' : '') + date.getDate();
var MM = ((date.getMonth() + 1) < 10 ? '0' : '') + (date.getMonth() + 1);
var yyyy = date.getFullYear();
var hours = (date.getHours() < 10 ? '0' : '') + date.getHours();
var minutes = (date.getMinutes() < 10 ? '0' : '') + date.getMinutes();
return (dd + "." + MM + "." + yyyy + ' ' + hours + ':' + minutes);


var d = document;
d.w = d.writeln;
var date = new Date("Mon Mar 25 2019 00:00:00 GMT+0100 (CET)");

/* this works */
d.w( formatDateTimeToString(date)+"<BR>");

// output:
// 24.03.2019 16:00


You may get NaN as a result in Safari if you attempt to instantiate a Date object with a string containing hyphens, as follows:



var d = document;
d.w = d.writeln;

date = new Date("2019-03-24");
/* returns NaN */
d.w( formatDateTimeToString(date)+"<BR>");

date = new Date("03-24-2019");
/* this fails with NaN*/
d.w( formatDateTimeToString(date)+"<BR>");





share|improve this answer

























  • This seems to be off topic. While the issue may be how the OP is generating their Date, the question starts with a Date object so you/we really don't know yet. This should just be a comment, there are many, many questions already about parsing.

    – RobG
    Mar 24 at 23:17













0












0








0







If the date object for Safari is generated the same way as it is done for Chrome, then at least in my old version of Safari the code runs successfully, as follows:



function formatDateTimeToString(date) 
var dd = (date.getDate() < 10 ? '0' : '') + date.getDate();
var MM = ((date.getMonth() + 1) < 10 ? '0' : '') + (date.getMonth() + 1);
var yyyy = date.getFullYear();
var hours = (date.getHours() < 10 ? '0' : '') + date.getHours();
var minutes = (date.getMinutes() < 10 ? '0' : '') + date.getMinutes();
return (dd + "." + MM + "." + yyyy + ' ' + hours + ':' + minutes);


var d = document;
d.w = d.writeln;
var date = new Date("Mon Mar 25 2019 00:00:00 GMT+0100 (CET)");

/* this works */
d.w( formatDateTimeToString(date)+"<BR>");

// output:
// 24.03.2019 16:00


You may get NaN as a result in Safari if you attempt to instantiate a Date object with a string containing hyphens, as follows:



var d = document;
d.w = d.writeln;

date = new Date("2019-03-24");
/* returns NaN */
d.w( formatDateTimeToString(date)+"<BR>");

date = new Date("03-24-2019");
/* this fails with NaN*/
d.w( formatDateTimeToString(date)+"<BR>");





share|improve this answer















If the date object for Safari is generated the same way as it is done for Chrome, then at least in my old version of Safari the code runs successfully, as follows:



function formatDateTimeToString(date) 
var dd = (date.getDate() < 10 ? '0' : '') + date.getDate();
var MM = ((date.getMonth() + 1) < 10 ? '0' : '') + (date.getMonth() + 1);
var yyyy = date.getFullYear();
var hours = (date.getHours() < 10 ? '0' : '') + date.getHours();
var minutes = (date.getMinutes() < 10 ? '0' : '') + date.getMinutes();
return (dd + "." + MM + "." + yyyy + ' ' + hours + ':' + minutes);


var d = document;
d.w = d.writeln;
var date = new Date("Mon Mar 25 2019 00:00:00 GMT+0100 (CET)");

/* this works */
d.w( formatDateTimeToString(date)+"<BR>");

// output:
// 24.03.2019 16:00


You may get NaN as a result in Safari if you attempt to instantiate a Date object with a string containing hyphens, as follows:



var d = document;
d.w = d.writeln;

date = new Date("2019-03-24");
/* returns NaN */
d.w( formatDateTimeToString(date)+"<BR>");

date = new Date("03-24-2019");
/* this fails with NaN*/
d.w( formatDateTimeToString(date)+"<BR>");






share|improve this answer














share|improve this answer



share|improve this answer








edited Mar 25 at 6:15

























answered Mar 24 at 18:51









slevy1slevy1

3,33211930




3,33211930












  • This seems to be off topic. While the issue may be how the OP is generating their Date, the question starts with a Date object so you/we really don't know yet. This should just be a comment, there are many, many questions already about parsing.

    – RobG
    Mar 24 at 23:17

















  • This seems to be off topic. While the issue may be how the OP is generating their Date, the question starts with a Date object so you/we really don't know yet. This should just be a comment, there are many, many questions already about parsing.

    – RobG
    Mar 24 at 23:17
















This seems to be off topic. While the issue may be how the OP is generating their Date, the question starts with a Date object so you/we really don't know yet. This should just be a comment, there are many, many questions already about parsing.

– RobG
Mar 24 at 23:17





This seems to be off topic. While the issue may be how the OP is generating their Date, the question starts with a Date object so you/we really don't know yet. This should just be a comment, there are many, many questions already about parsing.

– RobG
Mar 24 at 23:17



















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55324774%2fjavascript-date-object-getdate-getmonth-and-getfullyear-of-date-object-i%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript