Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove the letter "Z" from the end of a dateTime

Tags:

javascript

I am trying to remove the Z from the end of a dateTime entity. The timezone of the API gets confused from the site I'm pushing the date from. Does anyone know a script that can remove the Z when a user types in a dateTime?

like image 888
Rob DiDonna Avatar asked Jun 30 '17 15:06

Rob DiDonna


1 Answers

You're using UTC Date i'm guessing. You can try to use .toLocaleString() on your date time object.

Example

var datetime = new Date();
var now = datetime.toLocaleString();

This should get you something like this: 6/30/2017, 8:47:15 AM

Another option if you want to maintain the format and just remove the T and Z characters is to replace the strings. Example:

var datetime = new Date();
var now = datetime.toISOString().replace('Z', '').replace('T', '');
like image 56
Arman Peiravi Avatar answered Sep 16 '22 12:09

Arman Peiravi