syncCampaignDetails(){
let dateTime = {};
let date = this._root.getElementById("dateField").value;
// let time = this._root.getElementById("timeField").value;
// dateTime.date = date;
// dateTime.time = time;
// var newstr = date.replace(IST, '');
let toUtc = new Date(date).toISOString();
// var isoDate = new Date('yourdatehere').toISOString();
console.log(toUtc)
}
<mwc-textfield type="date" required class="date" id="dateField" min="${this.minDate}" max="${this.date}" value="${this.eventStart}"></mwc-textfield>
<mwc-textfield type="time" name="appt" required class="time" id="timeField" min="9:00" max="24:00"></mwc-textfield>
<button class="syncBtn layout vertical" on-click=${e => this.syncCampaignDetails(e)}>
<div class="labelText" id="sync">${__.gettext("Sync")}</div>
</button>
用户必须提供事件日期和事件的开始时间以及结束时间。 我的要求是将事件日期和开始时间转换为UTC格式。结束时间也一样。
syncCampaignDetails(){
let date = this._root.getElementById("dateField").value;
let toUtc = new Date(date).toUTCString();
console.log(toUtc)
}
` 日期,开始时间,结束时间也是不同的输入字段。如何通过约会时间。有人可以帮我吗?
答案 0 :(得分:1)
这是您可以做的。
我修改了代码段,使其在代码段中可以正常工作,但是 syncCampaignDetails是您所需要的。
function syncCampaignDetails() {
let dateTime = {};
let date = document.getElementById("dateField").value;
let time = document.getElementById("timeField").value;
dateTime.date = date;
dateTime.time = time;
let toUtc = new Date(`${dateTime.date}T${dateTime.time}`).toISOString();
document.querySelector('#convertedString').innerText = `UTC Time: ${toUtc}`;
}
document.querySelector('#sync').addEventListener('click', syncCampaignDetails)
#convertedString {
padding: 10px;
}
<input type="date" required class="date" id="dateField" min="${this.minDate}" max="${this.date}" />
<input type="time" name="appt" required class="time" id="timeField" min="9:00" max="24:00" />
<button class="syncBtn layout vertical" on-click=${e=>
<div class="labelText" id="sync">Convert</div>
</button>
<div id='convertedString'>
</div>