convert Javascript timestamp into UTC format [duplicate] - javascript

This question already has answers here:
How do I get a UTC Timestamp in JavaScript?
(16 answers)
Closed 7 years ago.
For example if you receive a timestamp in Javascript:
1433454951000
How would you create a function to convert the timestamp into UTC like:
2015/6/4 GMT+7

var d1 = new Date("UNIX TIME STAMP HERE");
d1.toUTCString()
Originally asked here:
How do I get a UTC Timestamp in JavaScript?

Related

How to convert javascript date object ( since Unix epoch ) to date in RFC 3339? [duplicate]

This question already has answers here:
How do I format a date in JavaScript?
(68 answers)
Closed 2 years ago.
I want to convert the JavaScript date object
let date = Date.now();
to date in RFC 3339 format, so it would return like this:
2020-05-21T08:01:48+00:00
How can I convert it? Get Help! Thank you!~
Try toISOString.
new Date('2020-05-21 08:01:48').toISOString()

How to convert existing UTC string to local timezone string in JavaScript? [duplicate]

This question already has answers here:
JavaScript - Parse UTC Date
(4 answers)
How to show a UTC time as local time in a webpage?
(5 answers)
Working with timezones and daylight savings time in Javascript
(3 answers)
How to convert time correctly across timezones?
(3 answers)
Closed 4 years ago.
I have a string:
var utc_datetime = "02/09/2018 1:27 a.m."
I need it to show up in the user's local time. The format will always be the same, and it will always be queried in UTC timezone.
How can I accomplish this? I tried moment, and moment-timezone, but no luck so far.
Remove the dots and capitalize the AM or PM: Append 'UTC' to the string then convert it to a date
var utc_datetime = "02/09/2018 1:27 a.m."
var new_datestring = utc_datetime.replace(/\./g,'').toUpperCase() + ' UTC';
var date = new Date(new_datestring);
var local_datetime = date.toString();
console.log(local_datetime)

current date time to dd-mon-yyyy hh:mm:ss [duplicate]

This question already has answers here:
How do I format a date in JavaScript?
(68 answers)
Where can I find documentation on formatting a date in JavaScript?
(39 answers)
Format JavaScript date as yyyy-mm-dd
(50 answers)
Javascript format date / time [duplicate]
(5 answers)
Get String in YYYYMMDD format from JS date object?
(53 answers)
Closed 5 years ago.
In javascript I need to change the current date in the following format?I googled a lot but I didnt find the exact result.
I'm expecting the current date to format is 22-Sep-2017 13:37:02
Thanks in Advance
var ele = document.getElementsByTagName('h3')[0];
setInterval(function(){
var date =new moment().format('DD-MMM-YYYY hh:mm:ss');
ele.innerHTML = date;}
,1000);
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.18.1/moment.js"></script>
<h3></h3>
Use momentjs and format your date according to your need.

How to convert mysql datetime to client datetime? [duplicate]

This question already has answers here:
Convert UTC date time to local date time
(38 answers)
Closed 9 years ago.
Lets say my server is in one country, and the client is in another, date like:
2014/12/24 12:00:00
how to convert it to the client-browser time?
new Date('2014/12/24 12:00:00').toLocaleString();
Source: http://www.w3schools.com/jsref/jsref_tolocalestring.asp

How can I convert milliseconds to date and time string? [duplicate]

This question already has answers here:
How to convert milliseconds into a readable date?
(7 answers)
Closed 9 years ago.
can I convert milliseconds to date and time string. suppose I have millisecond in a long number and I want it like this:
Oct 22 2013 09:50:17
is this possible??
Like this:
var date = new Date(1324339212260);
date.toString("MMM dd");

Categories