Reputation: 1055
I want to get gmt date for my js file. so want to know how i can get date. i dont want get date from computer, i want correct gmt date using js file.
I want to know how i can do this?
Do i need to use jQuery or what.
I need to match date in my codes.
suppose:
I have this codes from stack overflow
var date = 11;
var month = 10;
var year = 2012
function Checkday() {
if ( !isExpired() ) {
start();
} else {
stop();
};
};
function isExpired() {
var current = new Date();
current = current.getTime();
var dateToCheck = new Date();
dateToCheck.setFullYear(year);
dateToCheck.setMonth(month);
dateToCheck.setDate(date)
var checkdate = dateToCheck.getTime();
return checkdate < current
}
This code checking date from system or we can say checking computer time and date. And i dont want that. because if we decrease time in computer time my js file will start working even if time is over.
Any solution.
With php its very easy but i cant use any php in this.
Thanks in advance
Upvotes: 1
Views: 125
Reputation: 147403
You can create a date instance from UTC values using Date.UTC
:
var date = 11;
var month = 10;
var year = 2012
var utcDate = new Date(Date.UTC(year, --month, date));
or if you have a UTC time value (milliseconds since 1970-01-01T00:00:00Z) you can give it to the Date constructor directly:
var dateObj = new Date(timeValue)
And read back UTC values using the getUTC*
methods.
As Harry said, to get an accurate time, you need to access some other resource, an AJAX request to your server may suit. In that case, don't bother with a client side date object, just send the expiry details and get the sever to work it out and send a simple yes/no or true/false reply.
Upvotes: 1