admin 管理员组文章数量: 1086019
I'm using Ionic 3. I used ion-datetime ponent:
myDate: String = new Date().toISOString();
<ion-datetime displayFormat="HH:mm" pickerFormat="HH:mm" [(ngModel)]="myDate"></ion-datetime>
I want to have today's date that depends on the timezone of the user device. Unfortunately new Date().toISOString() always returns the GMT one. any advises how to this properly ?
I'm using Ionic 3. I used ion-datetime ponent:
myDate: String = new Date().toISOString();
<ion-datetime displayFormat="HH:mm" pickerFormat="HH:mm" [(ngModel)]="myDate"></ion-datetime>
I want to have today's date that depends on the timezone of the user device. Unfortunately new Date().toISOString() always returns the GMT one. any advises how to this properly ?
Share Improve this question asked Aug 8, 2017 at 20:16 MelchiaMelchia 24.4k23 gold badges108 silver badges129 bronze badges3 Answers
Reset to default 5If you use toLocalString()
it gives you the following format MM/DD/YYYY, HH:MM:SS A
If you need the a ISO 8601 format consider using the below code:
mydate: String = (new Date(Date.now() - (new Date()).getTimezoneOffset() * 60000)).toISOString().slice(0, -1);
try using the toLocaleString()
function of the Javascript Date Object.
myDate: String = new Date().toLocaleString();
Hope this helps.
- Open console at root proyect and install moment:
npm install moment --S
. - Import moment in ponent file:
import moment from 'moment';
. - Set value of model variable:
this.myDate = moment().format()
.
Check this post for more details: https://stackoverflow./a/47843362/7829826
本文标签:
版权声明:本文标题:javascript - Ionic ion-datetime - default it to the date and time with the timezone of the user's device - Stack Overflo 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://roclinux.cn/p/1744005434a2517202.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论