I have a date that comes from a Bootstrap DateTimePicker $('#datetimepicker').find("input").val()
that has the format "mm/dd/yyyy".
<div class='input-group date' id='datetimepicker'>
<form autocomplete="off" onkeydown="return event.key != 'Enter';">
<input type='text' autofill="off" readonly class="form-control" />
</form>
<span class="input-group-addon">
<span class="glyphicon glyphicon-calendar"></span>
</span>
</div>
I'm trying to get the UTC date and time for the selected date, at midnight, using Moment js
:
moment.utc($('#datetimepicker').find("input").val()).tz(timezone).format('YYYY-MM-DD HH:mm:ss')
For example, starting date from the picker is 01/21/2022
and the timezone
is America/Phoenix
which is UTC-7
.
I should have 2022-01-21 07:00:00
but my code returns 2022-01-20 17:00:00
.
What am I doing wrong? Is there a way to get the UTC time for a day at 00:00 time, just by knowing the timezone?