javascript - Datetime parser function keeps returning days on Tuesday -
for reason, datetime parser keeps returning dates tuesday, idea why?
for example:
<div class="datetime">2015-06-04 16:00:00</div> <div class="datetime">2015-06-05 13:00:00</div>
output
tuesday 04 june - 16:00 tuesday 05 june - 13:00
code
html
<div class="datetime">2015-06-04 16:00:00</div> <div class="datetime">2015-06-05 13:00:00</div>
js
$('.datetime').each(function () { var value = $(this).text().trim().split(' '), date = value[1].split(':'), day = value[0].split('-'), days = ['monday','tuesday','wednesday','thursday','friday','saturday','sunday'], months = ['january','february','march','april','may','june','july','august','september','october','november','december']; date.pop(); $(this).html(days[new date(date.parse('2015-05-04')).getday()] +' '+day[2]+' '+ months[new date(date.parse(value[0])).getmonth()] + ' - ' + date[0] + ':' + date[1]); });
jsfiddle link
you have given hard coded date! change : value[0]
$(this).html(days[new date(date.parse(value[0])).getday()] +' '+day[2]+' '+ months[new date(date.parse(value[0])).getmonth()] + ' - ' + date[0] + ':' + date[1]);
Comments
Post a Comment