Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

222
Views
How to merge Date and Time using Javascript

I am new to JavaScript and don't know much. I know there are already many similar questions available but I didn't get what I was looking for. I am having 2 inputs one is datePicker and other one is timePicker.

<form>
<div class="form-group">
<label for="a">Date :</label>
<input class="form-control" ng-model="res.Date" ng-required="true" type="date" >
</div>
<div class="form-group">
<label for="a">Time :</label>
<input class="form-control timepicker" ng-model="res.Time" ng-required="true" 
type="time">
</div>
</form>

I am getting date and time separately and in different format - I have converted the date in yyyy/mm/dd format and also formatted the time using the below code -

 var timeString = $scope.res.Time.getHours() + ':' + $scope.res.Time.getMinutes() + ':00';
 var d = new Date($scope.res.Date),
 month = '' + (d.getMonth() + 1),
 day = '' + d.getDate(),
 year = d.getFullYear();
 if (month.length < 2)
 month = '0' + month;
 if (day.length < 2)
 day = '0' + day;
 var fdate = [year, month, day].join('-')

I am getting date and time like -

Time = 20:42:00
Date = 2021-08-11

But now I want to join them and want to make it like this = 2021-08-10T01:01:55.216Z

I tried few things like parsing but that didn't given me this format. Sorry for the mistakes. Please Help me in getting this. Thank you

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

let time = "20:42:00";
let date = new Date("2021-08-11");

let parsedDate = new Date(Date.parse(date.toDateString() + ' ' + time));

console.log(parsedDate.toISOString());

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!