나는 momentJS와 시간을 비교하려고합니다. 여기 여기 시간을 MomentJS와 비교
$(document).ready(function() {
var today =moment();
console.log(today.format("hh:mm"));
if((today.format('D') == (moment().day("Sunday").format('D')) || (today.format('D') == moment().day('Saturday').format('D'))))
{
$('.kompensasi').val("100,000");
$('.chk').hide();
}
else{
if((today.format("hh:mm") > moment('00:00', 'hh:mm')) && (today.format("hh:mm") < moment('03:00', 'hh:mm')))
{
$('.kompensasi').val("30,000");
$('.cekbok').val('');
}else{
$('.cekbok').val('Dapet RO 1');
$('.kompensasi').val("0");
}
}
});
내 스크립트
것은 내 양식 내가이 resullt01:44
을 얻을
console.log(today.format("hh:mm"))
에서
<div class="col-sm-7">
Kompensasi : <input name="dapet" type="text" readonly class="kompensasi" />
</div>
</div>
<div class="form-group chk">
<label class="col-sm-3 control-label">Ro</label>
<div class="col-sm-7">
<input type="text" class='cekbok' name='rostatus' />
</div>
</div>
입니다.
위의 스크립트를 사용하면 항상 else
으로 이동하므로 문제를 해결할 수있는 방법이 있습니까?
다음은 숫자로 순간을 변환 할 필요가 ==
또는 <
또는 >
사용하려면 내 바이올린 https://jsfiddle.net/s9wfh9ye/33/
내 Upated 질문
var today =moment();
var after = moment(today.format("hh:mm")).isAfter(moment('00:00', "hh:mm"));
var before = moment(today.format("hh:mm")).isBefore(moment('03:00', "hh:mm"));
today.format('hh:mm').valueOf() -->02:17
moment('00:00', 'hh:mm').valueOf() --> 1472058000000
moment('03:00', 'hh:mm').valueOf() -->1472068800000
console.log(after); // false
console.log(before); // false
[순간 js 날짜 시간 비교] 가능한 복제본 (http://stackoverflow.com/questions/22600856/moment-js-date-time-comparison) –
순간 ('00 : 00 ','hh : mm ')'는 'today.format ("hh : mm")'이 문자열을 반환하므로 그것들을 비교해서는 안됩니다. –
@ArunPJohny : 문자열을 시간과 비교하지 마십시오. 대신 정수를 비교하십시오. '.valueOf()'를 사용하여 순간을 유닉스 타임 스탬프로 변환하십시오. – slebetman