-1

The following script generates the following output: "Sun Feb 23 2020 06:35:14 GMT-1000 (HST)"

I would like to strip out "GMT-1000 " and display only "Sun Feb 23 2020 06:35:14 (HST)".

I don't know where the GMT-1000 is generated, so can't understand how to implement

str.replace("GMT-1000", " ");

What can I do?

function display_c(){
var refresh=1000; // Refresh rate in milli seconds
mytime=setTimeout('display_ct()',refresh)
}

function display_ct() {
var x = new Date()
document.getElementById('ct').innerHTML = x;
var ct = str.replace("GMT-1000", " ");      
display_c();
 }
Konabob
  • 1
  • 3

2 Answers2

0

try this

const date  = 'Sun Feb 23 2020 06:35:14 GMT-1000 (HST)';
const convertDate = date => new Date(date).toUTCString().split(' ').slice(0, 5).join(' ');
console.log(convertDate(date));
Ghoul Ahmed
  • 4,446
  • 1
  • 14
  • 23
0

The information comes from system's time-zone offset from the Greenwich Mean Time (GMT).

You can use Javascript Date prototype to handle dates.

So that:

let yourDate = "Sun Feb 23 2020 06:35:14 GMT-1000 (HST)"

If hours do not matter:

let simplifiedDate = new Date(yourDate).toDateString()
// returns "Sun Feb 23 2020"

If you want something locale specific:

let localeDate = new Date(yourDate).toLocaleString()
// may return "2/23/2020, 1:35:14 PM"

Or if you really want just the string in that format, you can do:

yourDate.toString().substring(0, yourDate.indexOf(' GMT'))
// returns "Sun Feb 23 2020 13:35:14"

Hope this helps!

zOnNet
  • 86
  • 5
  • I thank you for a quick response. I am a perl programmer, just starting to learn javascript. This option looks like it might work for me: yourDate.toString().substring(0, yourDate.indexOf(' GMT')) However I am not sure how to get it intigrated with my original script. – Konabob Feb 23 '20 at 19:01