createAlarm({
active: true,
date: picked_Date.toISOString(),
message: 'sample alarm',
snooze: 1,
});
I created an alarm using DatePicker(react-native-date-picker), and react-native-simple-alarm
...
<Text>{date}</Text> // 2022-02-16T08:47:25.352Z
i just want HH : MM value in 24hours, like 13:42, 09:50 or 22:10. so i tried this code
<Text>{moment(date).format('hh:mm')}</Text> // 05:47
This did give me hh:mm formed value, but the value was not the same as my computer and ios simulator it was supposed to 08:47, cause the {date} was 2022-02-16T08:47:25.352Z
How can I get rid of the time difference? and set moment's time zone globally as same as the hardware(simulator or phone)?
CodePudding user response:
try moment.utc()
. it will adjust your input time to UTC so you will the time you want.
also hh:mm
will give 12 hour clock time so you will need HH:mm
for 24 hour clock
//12 hr clock
var a = moment.utc('2022-02-16T08:47:25.352Z').format('hh:mm');
var b = moment.utc('2022-02-16T18:47:25.352Z').format('hh:mm');
console.log(a)
console.log(b)
//24 hr clock
var c = moment.utc('2022-02-16T08:47:25.352Z').format('HH:mm');
var d = moment.utc('2022-02-16T18:47:25.352Z').format('HH:mm');
console.log(c)
console.log(d)
<script src="http://cdnjs.cloudflare.com/ajax/libs/moment.js/2.2.1/moment.min.js"></script>