Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

how can I get hh:mm time from ISO without any time difference

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

How can I get rid of the time difference?
and set moment’s time zone globally as same as the hardware(simulator or phone)?

>Solution :

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>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading