var DateString=(new Date("")).toString();
1-How do you get the DateString to give you the Date Time format that
you want ?
You manually get the components and format them yourself. If you let
the UA write it out itself, the ECMAScript spec says:
15.9.5.3 Date.prototype.toDateString ( )
This function returns a string value. The contents of the string are
implementation-dependent, but are intended to represent the "date"
portion of the Date in the current time zone in a convenient, human-
readable form.
In other words, it depends on the UA and user settings, you can't
control it programmatically unless you replace the Date object's
toString method (which may not be a good idea).
Date.prototype.toString = function(){
function addZ(n){return (n<10)? '0'+n:''+n;}
var d = this;
return d.getFullYear() + '/'
+ addZ(d.getMonth()+1) + '/'
+ addZ(d.getDate()) + ' '
+ addZ(d.getHours()) + ':'
+ addZ(d.getMinutes()) + ':'
+ addZ(d.getSeconds());
}
Some old browsers may not support getFullYear(), you may want to test
and provide a fallback. Ensure your dates are suitable for
international use.
2- How can you add a few more seconds to that Date value and display
it again.
Something like:
var aFewMoreSeconds = 5;
var now = new Date();
now.setSeconds(now.getSeconds() + aFewMoreSeconds);
or
now = new Date(now.getTime() + aFewMoreSeconds*1e3);
Perhaps that needs to be converted into a large value in seconds ,
added +2 seconds and then converted back to teh Date Time string.
Keep the date object as an object so you can easily work with it using
the built-in Date methods. Provide your own function to convert it to
a string only for display.