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

Actually I want to display like:

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>
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>
Another thing you can do is to use javascript's toLocaleString() method for more flexibility-
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};
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With