Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
61
rated 0 times [  62] [ 1]  / answers: 1 / hits: 38466  / 13 Years ago, wed, july 27, 2011, 12:00:00

I am trying to get the LocaleDateString and the LocaleTimeString which that would be toLocaleString() but LocaleString gives you GMT+0100 (GMT Daylight Time) which I wouldn't it to be shown.



Can I use something like:



timestamp = (new Date()).toLocaleDateString()+toLocaleTimeString();


Thanks alot


More From » gettime

 Answers
27

You can use the local date string as is, just fiddle the hours, minutes and seconds.



This example pads single digits with leading 0's and adjusts the hours for am/pm.





function timenow() {
var now = new Date(),
ampm = 'am',
h = now.getHours(),
m = now.getMinutes(),
s = now.getSeconds();
if (h >= 12) {
if (h > 12) h -= 12;
ampm = 'pm';
}

if (m < 10) m = '0' + m;
if (s < 10) s = '0' + s;
return now.toLocaleDateString() + ' ' + h + ':' + m + ':' + s + ' ' + ampm;
}
console.log(timenow());




[#90987] Monday, July 25, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
zahrafrancisr

Total Points: 176
Total Questions: 105
Total Answers: 99

Location: Svalbard and Jan Mayen
Member since Sun, Sep 25, 2022
2 Years ago
;