我使用ES-AR浏览器中使用JavaScript的DateTime有问题。
这是一个选择每15天左右更改周期的选择。问题是当我想在阿根廷西班牙语中度过约会时,鉴于:m/d/yyyy到d/m/yyyy,然后打破了我的约会。我已经尝试了" If(ES-AR(",但这对我来说不是最好的解决方案。我想对一些可行解决方案有一个很好的答案。在这里,我非常感谢您。
function InitializeDropdownlistOfFirstOption(dropdownName, step) {
$('#fromPeriodValidation').hide();
$('#toPeriodValidation').hide();
var dropdownList = $('#' + dropdownName);
var timeperiod = dropdownList.val();
var reg = new RegExp("\.|-", "g");
var userLang = navigator.language || navigator.userLanguage;
if (String(userLang) == 'es-AR') {
alert(String(cultureInfo));
var formattimeperiod = timeperiod.replace(reg, "/");
if (formattimeperiod.split("/")[0] > 12) {
var tempDay = formattimeperiod.split("/")[0];
var tempMonth = formattimeperiod.split("/")[1];
var tempYear = formattimeperiod.split("/")[2];
formattimeperiod = tempMonth + "/" + tempDay + "/" + tempYear;
}
timeperiod = formattimeperiod;
}
var timeperioddate = new Date(timeperiod);
var month = timeperioddate.getMonth();
var day = timeperioddate.getDate();
var year = timeperioddate.getFullYear();
var option;
dropdownList.get(0).remove(0);
if (day <= 15) {
switch (step) {
case 1:
day = new Date(new Date(year, (month + 1) % 12, 1).getTime() - 1000 * 60 * 60 * 24).getDate();
option = new Date(year, month, day).format(pattern);
dropdownList.prepend("<option value='" + option + "'>" + option + "</option>");
break;
case -1:
month--;
if (month < 1) {
month += 12;
year--;
}
if (month == 12) {
day = 31;
} else {
day = new Date(new Date(year, (month + 1) % 12, 1).getTime() - 1000 * 60 * 60 * 24).getDate();
}
option = new Date(year, month, day).format(pattern);
dropdownList.prepend("<option value='" + option + "'>" + option + "</option>");
break;
}
} else {
switch (step) {
case 1:
month++;
if (month > 12) {
month = 1;
year++;
}
if (month == 12) {
day = 31;
} else {
day = new Date(new Date(year, (month) % 12, 1).getTime() - 1000 * 60 * 60 * 24).getDate();
}
option = new Date(year, month, 15).format(pattern);
dropdownList.prepend("<option value='" + option + "'>" + option + "</option>");
break;
case -1:
option = new Date(year, month, 15).format(pattern);
dropdownList.prepend("<option value='" + option + "'>" + option + "</option>");
break;
}
}
dropdownList.get(0).selectedIndex = 0;
}
<div class="timeperiod" id="timeperiod">
<div style="width: 40%;float: left">
<label class="lblTime"><b>From Time Period</b></label>
<form class="form">
<button type="button" class="btn btn-primary button" onclick="InitializeDropdownlistOfFirstOption('drpfromdatePeriod', -1)">< </button>
<select name="drpfromdatePeriod" class="drpdateperiod" id="drpfromdatePeriod" onchange="SelectPeriod('drpfromdatePeriod')"></select>
<button type="button" class="btn btn-primary button" onclick="InitializeDropdownlistOfFirstOption('drpfromdatePeriod', 1)">> </button>
<img src="@Url.ImportContent("~/Content/images/time_period_calendar.png")" class="imgCalendar" id="imgFromdate" />
</form>
<label class="lblTime"><b>To Time Period</b></label>
<form class="form">
<button type="button" class="btn btn-primary button" onclick="InitializeDropdownlistOfFirstOption('drptodatePeriod', -1)">< </button>
<select name="drptodatePeriod" class="drpdateperiod" id="drptodatePeriod" onchange="SelectPeriod('drptodatePeriod')"></select>
<button type="button" class="btn btn-primary button" onclick="InitializeDropdownlistOfFirstOption('drptodatePeriod', 1)">> </button>
<img src="@Url.ImportContent("~/Content/images/time_period_calendar.png")" class="imgCalendar" id="imgTodate" />
</form>
</div>
<div>
<input type="checkbox" id="cbVat" value="Only return expense receipts with VAT" onclick="SelectVat(this.checked)"/>
<label class="lblTime" id="lbVatMessage"> <b>Only return expense receipts with VAT</b></label>
<img src="@Url.ImportContent("~/Content/images/info.gif")" class="imgInfo" title="If this checkbox is selected, the application will only return receipts for expenses with VAT." />
</div>
</div>
我感谢任何帮助:D输入图像描述此处的图像描述在此处
尝试自己解决时间格式问题并不是最好的方法。
诸如MONMJS之类的库,例如moment.parseZone()
,它似乎为您解决了这些问题。