0

I am trying to convert string to time, the string i have are in this format, '8:3' and '16:45'.

I want to convert UTC time in jQuery.

4
  • 1
    Does this answer your question? How do you convert a JavaScript date to UTC? Commented Apr 8, 2020 at 5:15
  • i have string like " 8:3 ", i want convert this string to UTC time Commented Apr 8, 2020 at 5:20
  • what does 8:3 mean? Commented Apr 8, 2020 at 5:22
  • " 8:3 " is time i have this time in string Commented Apr 8, 2020 at 5:23

2 Answers 2

1

You can write your function to create UTC date with the time string.

function toUTC(str) {
  let [h, m] = str.split(':');
  let date = new Date();
  date.setHours(h, m, 0)
  return date.toUTCString();
}

console.log(toUTC('8:3'))
console.log(toUTC('16:45'))

Sign up to request clarification or add additional context in comments.

Comments

0

You don't need jQuery for such operations. Just the simple Date object will do the trick. Say you want to convert time from a specific date.

let date = new Date('2020-04-01'); // leave the Date parameter blank if today
date.setHours(16); // must be 24 hours format
date.setMinutes(45);
let theUTCFormat = date.getUTCDate();

Cheers,

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.