Thursday, May 23, 2024
 Popular · Latest · Hot · Upcoming
105
rated 0 times [  110] [ 5]  / answers: 1 / hits: 77749  / 7 Years ago, thu, august 17, 2017, 12:00:00

Have simple function which returns an error:




ERROR: date.toLocaleDateString is not a function




TypeError: date.toLocaleDateString is not a function
at FormatTime (../Src/rootdialog.js:87:58)


Function definition:



function FormatTime(time, prefix = ) {
var date = Date.parse(time);
return ((typeof time != undefined) ? prefix + date.toLocaleDateString() : );
}


Function receives Date object as input however even explicit conversion to Date with Date.parse() does not help. Using Node.js 8.x. Any solution?




P.S. Issue was caused by BotBuilder architecture.



More From » node.js

 Answers
14

Date.parse returns a number. You are looking for new Date. Or, if time already is a Date instance, just use time.toLocaleDateString() (and make sure it really is in every call to the function)!



function formatTime(time, prefix = ) {
return typeof time == object ? prefix + time.toLocaleDateString() : ;
}

[#56738] Tuesday, August 15, 2017, 7 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
anabeldaliad

Total Points: 552
Total Questions: 107
Total Answers: 120

Location: Hungary
Member since Mon, Feb 21, 2022
2 Years ago
anabeldaliad questions
Wed, Jul 21, 21, 00:00, 3 Years ago
Mon, Oct 26, 20, 00:00, 4 Years ago
Wed, May 6, 20, 00:00, 4 Years ago
Fri, May 1, 20, 00:00, 4 Years ago
;