3

I want to display only Day, Date, Time. Now it displays:

enter image description here

Actually I want to display like:

enter image description here

How to remove --- "(India Standard Time)"

Used code below:

<html>

<head>
  <title>(Type a title for your page here)</title>
  <script type="text/javascript">
    function display_c() {
      var refresh = 1000; // Refresh rate in milli seconds
      mytime = setTimeout('display_ct()', refresh)
    }

    function display_ct() {
      var strcount
      var x = new Date()
      document.getElementById('ct').innerHTML = x;
      tt = display_c();
    }
  </script>
</head>

<body onload=display_ct();>
  <span id='ct'></span>

</body>

</html>
kukkuz
  • 41,512
  • 6
  • 59
  • 95
vishnu
  • 2,848
  • 3
  • 30
  • 55

2 Answers2

3

Try with some Regex pattern /GMT(.*)/g .toString() used to convert as a string for replace GMT and after all.

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

    function display_ct() {
      var strcount
      var x = new Date()
      document.getElementById('ct').innerHTML = x.toString().replace(/GMT(.*)/g,"");
      tt = display_c();
    }
display_ct()
  <span id='ct'></span>
prasanth
  • 22,145
  • 4
  • 29
  • 53
1

Another thing you can do is to use javascript's toLocaleString() method for more flexibility-

  1. It has options to format the string that you can specify - for instance in the demo below I'm using:

    var options = { weekday: 'short', year: 'numeric', month: 'short', day: 'numeric', hour: 'numeric', minute: 'numeric', second: 'numeric', hour12: false};
    
  2. Now you can display the date string using this:

    document.getElementById('ct').innerHTML = x.toLocaleString('en-US', options);
    

See demo below:

<html>

<head>
  <title>(Type a title for your page here)</title>
  <script type="text/javascript">
    var options = { weekday: 'short', year: 'numeric', month: 'short', day: 'numeric', hour: 'numeric', minute: 'numeric', second: 'numeric', hour12: false};
    function display_c() {
      var refresh = 1000; // Refresh rate in milli seconds
      mytime = setTimeout('display_ct()', refresh)
    }

    function display_ct() {
      var strcount;
      var x = new Date();
      document.getElementById('ct').innerHTML = x.toLocaleString('en-US', options);
      tt = display_c();
    }
  </script>
</head>

<body onload=display_ct();>
  <span id='ct'></span>

</body>

</html>
kukkuz
  • 41,512
  • 6
  • 59
  • 95