Shiv Shiv - 1 month ago 15
Javascript Question

Remove GMT+530(Indian standard Time) without changing current time in javascript

I am displaying current day,month,date,year and time like this

Mon Oct 24 2016 17:09:25 GMT+0530 (India Standard Time)​​​​​​​


but i need to display like this

Mon Oct 24 2016 17:09:25


my code in javascript:

var timestamp = new Date();
editor.insertHtml( 'The current date and time is: ' + timestamp.toString());


How can i do this please can anyone tell me how to do this.

Thank you

Answer

If you are open to add a library, you should use moment.js

console.log(moment().format('ddd MMM DD YYYY hh:mm:ss'))
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.15.2/moment.min.js"></script>

If not, a small work around

var d = new Date().toString();
var index = d.lastIndexOf(':') +3
console.log(d.substring(0, index))

Note: moment approach is more preferred

Comments