The JavaScript Date object does not have full timezone support. Date objects allow only simple representations to denote a particular location's offset from Universal Coordinated Time (UTC). This is typically provided as a +/- offset from UTC-0 (also known as Greenwich Mean Time, or GMT) for example, +05:30 denotes that a location is 5 hours and 30 minutes ahead of UTC +00:00. The issue with this method is not getting the correct local time for a given date. The existing methods are sufficient for this purpose. The issue is correctly converting to and from local time and UTC for all points in time - in any of the past, present, and future - based on an initial time provided. This is important for defining relative dates, where a time in a given location may observe different UTC offsets, according to any Daylight Savings Rules (DST) in effect or any other changes that may occur to a location's time zone over time. Without the communication of the explicit time zone rules governing a given date and time, the ability to effectively calculate the offset of the local time to UTC or to any other time zone at any point in the past or future is lost.
This API can be used to get TZDate objects with full time zone support, convert them between timezones, retrieve available timezones.
For more information on the Time features, see Time Guide.
Since: 2.4
Interface | Method |
---|---|
TimeManagerObject | |
TimeUtil |
DOMString getLocalTimezone ()
DOMString[] getAvailableTimezones ()
DOMString getDateFormat (optional boolean? shortformat)
DOMString getTimeFormat ()
boolean isLeapYear (long year)
void setDateTimeChangeListener (SuccessCallback changeCallback)
void unsetDateTimeChangeListener ()
void setTimezoneChangeListener (SuccessCallback changeCallback)
void unsetTimezoneChangeListener () |
TZDate |
long getDate ()
void setDate (long date)
long getDay ()
long getFullYear ()
void setFullYear (long year)
long getHours ()
void setHours (long hours)
long getMilliseconds ()
void setMilliseconds (long ms)
long getMinutes ()
void setMinutes (long minutes)
long getMonth ()
void setMonth (long month)
long getSeconds ()
void setSeconds (long seconds)
long getUTCDate ()
void setUTCDate (long date)
long getUTCDay ()
long getUTCFullYear ()
void setUTCFullYear (long year)
long getUTCHours ()
void setUTCHours (long hours)
long getUTCMilliseconds ()
void setUTCMilliseconds (long ms)
long getUTCMinutes ()
void setUTCMinutes (long minutes)
long getUTCMonth ()
void setUTCMonth (long month)
long getUTCSeconds ()
void setUTCSeconds (long seconds)
DOMString getTimezone ()
TZDate toTimezone (DOMString tzid)
boolean earlierThan (TZDate other)
DOMString toLocaleDateString ()
DOMString toLocaleTimeString ()
DOMString toLocaleString ()
DOMString toDateString ()
DOMString toTimeString ()
DOMString toString ()
long secondsFromUTC ()
boolean isDST ()
|
TimeDuration |
boolean equalsTo (TimeDuration other)
boolean lessThan (TimeDuration other)
boolean greaterThan (TimeDuration other) |
enum TimeDurationUnit { "MSECS", "SECS", "MINS", "HOURS", "DAYS" };
Since: 2.4
At least the following values must be supported:
[NoInterfaceObject] interface TimeManagerObject {
readonly attribute TimeUtil time;
};
Tizen implements TimeManagerObject;
Since: 2.4
There will be a tizen.time object that allows accessing the functionality of the Time API.
[NoInterfaceObject] interface TimeUtil {
TZDate getCurrentDateTime() raises(WebAPIException);
DOMString getLocalTimezone() raises(WebAPIException);
DOMString[] getAvailableTimezones() raises(WebAPIException);
DOMString getDateFormat(optional boolean? shortformat) raises(WebAPIException);
DOMString getTimeFormat() raises(WebAPIException);
boolean isLeapYear(long year) raises(WebAPIException);
void setDateTimeChangeListener(SuccessCallback changeCallback) raises(WebAPIException);
void unsetDateTimeChangeListener() raises(WebAPIException);
void setTimezoneChangeListener(SuccessCallback changeCallback) raises(WebAPIException);
void unsetTimezoneChangeListener() raises(WebAPIException);
};
Since: 2.4
This interface offers methods to manage date/time as well as timezones such as:
getCurrentDateTime
TZDate getCurrentDateTime();
Since: 2.4
Return value:
TZDate The current TZDate objectExceptions:
with error type UnknownError, if the call failed due to an unknown error.
Code example:
var current_dt = tizen.time.getCurrentDateTime();
console.log("current date/time is " + current_dt.toLocaleString());
getLocalTimezone
DOMString getLocalTimezone();
Since: 2.4
Return value:
Timezone The local timezoneExceptions:
with error type UnknownError, if the call failed due to an unknown error.
Code example:
console.log("The local time zone is " + tizen.time.getLocalTimezone());
Code example:
// Note that it is possible to get the time zone description in other formats, e.g. by calling:
now = new tizen.TZDate(new Date(), 'Asia/Manila');
console.log(now.toString());
Output example:
Wednesday, January 27, 2016, 8:46:00 PM GMT+0800 Philippines Time
getAvailableTimezones
DOMString[] getAvailableTimezones();
Since: 2.4
Zero or more slashes separate different components of a timezone identifier, with the most general descriptor first and the most specific one last. For example, 'Europe/Berlin', 'America/Argentina/Buenos_Aires'.
Return value:
The array of time zone identifiersExceptions:
with error type UnknownError, if the call failed due to an unknown error.
Code example:
var tzids = tizen.time.getAvailableTimezones();
console.log("The device supports " + tzids.length + " time zones.");
Code example:
var tzids = tizen.time.getAvailableTimezones();
var currentLocation = 'Europe/Berlin';
// checks whether an entry 'Europe/Berlin' exists in the array.
if (tzids.indexOf(currentLocation) > -1) {
console.log('The device supports ' + currentLocation + ' timezone.');
} else {
console.log('The device does not support ' + currentLocation + ' timezone.');
}
getDateFormat
DOMString getDateFormat(optional boolean? shortformat);
Since: 2.4
Gets the date format according to the system's locale settings.
These expressions may be used in the returned string:
Examples of string formats include: "d/m/y", "y-d-m", "D, M d y".
Parameters:
Return value:
DOMString The date format according to the system's locale settingsExceptions:
with error type UnknownError, if the call failed due to an unknown error.
Code example:
// Gets the long date format, e.g. "D, M d y".
var dateFormat = tizen.time.getDateFormat();
// Gets the short date format, e.g. "d/m/y".
var shortDateFormat = tizen.time.getDateFormat(true);
console.log("Long date format: " + dateFormat);
getTimeFormat
DOMString getTimeFormat();
Since: 2.4
Gets the time format according to the system's locale settings.
These expressions may be used in the returned string:
Examples of string formats include: "h:m:s ap", "h:m:s".
Return value:
DOMString The time format according to the system's locale settingsExceptions:
with error type UnknownError, if the call failed due to an unknown error.
Code example:
// Gets the time format, e.g. "h:m:s ap".
var timeFormat = tizen.time.getTimeFormat();
console.log(timeFormat);
isLeapYear
boolean isLeapYear(long year);
Since: 2.4
Parameters:
Return value:
boolean true, if the year is a leap yearExceptions:
with error type TypeMismatchError, if the input parameter is not compatible with the expected type for that parameter.
with error type InvalidValuesError, if any of the input parameters contain an invalid value.
with error type UnknownError, if the call failed due to an unknown error.
Code example:
var current_dt = tizen.time.getCurrentDateTime();
var is_leap = tizen.time.isLeapYear(current_dt.getFullYear());
if (is_leap) {
console.log("This year is a leap year.");
}
setDateTimeChangeListener
void setDateTimeChangeListener(SuccessCallback changeCallback);
Since: 2.4
Listener set with setTimezoneChangeListener() method is called when device time was set by the user.
Parameters:
Exceptions:
with error type TypeMismatchError, if the input parameter is not compatible with the expected type for that parameter.
with error type UnknownError, if the call failed due to an unknown error.
Code example:
var changedCallback = function() {
try {
var current_dt = tizen.time.getCurrentDateTime();
console.log("current date/time is " + current_dt.toLocaleString());
} catch (err) {
console.log (err.name + ": " + err.message);
}
};
tizen.time.setDateTimeChangeListener(changedCallback);
unsetDateTimeChangeListener
void unsetDateTimeChangeListener();
Since: 2.4
Exceptions:
with error type UnknownError, if the call failed due to an unknown error.
Code example:
var changedCallback = function() {
try {
var current_dt = tizen.time.getCurrentDateTime();
console.log("current date/time is " + current_dt.toLocaleString());
tizen.time.unsetDateTimeChangeListener();
} catch (err) {
console.log (err.name + ": " + err.message);
}
};
tizen.time.setDateTimeChangeListener(changedCallback);
setTimezoneChangeListener
void setTimezoneChangeListener(SuccessCallback changeCallback);
Since: 2.4
Listener set with setTimezoneChangeListener() method is called when device time zone has changed.
Parameters:
Exceptions:
with error type TypeMismatchError, if the input parameter is not compatible with the expected type for that parameter.
with error type UnknownError, if the call failed due to an unknown error.
Code example:
var changedCallback = function() {
try {
// The new time zone can be retrieved through tizen.time.getLocalTimezone()
var zone = tizen.time.getLocalTimezone();
console.log("current time zone is " + zone);
} catch (err) {
console.log (err.name + ": " + err.message);
}
};
tizen.time.setTimezoneChangeListener(changedCallback);
unsetTimezoneChangeListener
void unsetTimezoneChangeListener();
Since: 2.4
Exceptions:
with error type UnknownError, if the call failed due to an unknown error.
Code example:
var changedCallback = function() {
try {
var zone = tizen.time.getLocalTimezone();
console.log("current time zone is " + zone);
tizen.time.unsetTimezoneChangeListener();
} catch (err) {
console.log (err.name + ": " + err.message);
}
};
tizen.time.setTimezoneChangeListener(changedCallback);
[Constructor(optional Date? datetime, optional DOMString? timezone),
Constructor(long year, long month, long day, optional long? hours, optional long? minutes, optional long? seconds, optional long? milliseconds, optional DOMString? timezone)]
interface TZDate {
long getDate();
void setDate(long date);
long getDay();
long getFullYear();
void setFullYear(long year);
long getHours();
void setHours(long hours);
long getMilliseconds();
void setMilliseconds(long ms);
long getMinutes();
void setMinutes(long minutes);
long getMonth();
void setMonth(long month);
long getSeconds();
void setSeconds(long seconds);
long getUTCDate();
void setUTCDate(long date);
long getUTCDay();
long getUTCFullYear();
void setUTCFullYear(long year);
long getUTCHours();
void setUTCHours(long hours);
long getUTCMilliseconds();
void setUTCMilliseconds(long ms);
long getUTCMinutes();
void setUTCMinutes(long minutes);
long getUTCMonth();
void setUTCMonth(long month);
long getUTCSeconds();
void setUTCSeconds(long seconds);
DOMString getTimezone();
TZDate toTimezone(DOMString tzid) raises(WebAPIException);
TZDate toLocalTimezone() raises(WebAPIException);
TZDate toUTC() raises(WebAPIException);
TimeDuration difference(TZDate other) raises(WebAPIException);
boolean equalsTo(TZDate other) raises(WebAPIException);
boolean earlierThan(TZDate other) raises(WebAPIException);
boolean laterThan(TZDate other) raises(WebAPIException);
TZDate addDuration(TimeDuration duration) raises(WebAPIException);
DOMString toLocaleDateString();
DOMString toLocaleTimeString();
DOMString toLocaleString();
DOMString toDateString();
DOMString toTimeString();
DOMString toString();
long secondsFromUTC() raises(WebAPIException);
boolean isDST() raises(WebAPIException);
TZDate? getPreviousDSTTransition() raises(WebAPIException);
TZDate? getNextDSTTransition() raises(WebAPIException);
};
Since: 2.4
TZDate(optional Date? datetime, optional DOMString? timezone);
TZDate(long year, long month, long day, optional long? hours, optional long? minutes, optional long? seconds, optional long? milliseconds, optional DOMString? timezone);
Code example:
// Creates a new TZDate object with current date/time and timezone:
var now = new tizen.TZDate();
// Creates a new TZDate object with date set to 1st of January 2016 in time zone for Germany:
var newYear = new tizen.TZDate(new Date("2016-01-01"), 'Europe/Berlin');
// Creates a new TZDate object with values set explicitly:
var myDate = new tizen.TZDate(1999, 11, 31, 23, 59, 59, 999, 'Europe/Berlin');
getDate
long getDate();
Since: 2.4
Return value:
long The day of the month.Code example:
var someDate = new tizen.TZDate(1999, 11, 31, 23, 59, 59, 999, "Europe/London");
console.log(someDate.getDate()); // should output 31.
setDate
void setDate(long date);
Since: 2.4
If it tries to set the day bigger than the last day of the month or smaller than 1, it will be calculated automatically. For example, if TZDate's month is May and parameter is 32, it will be June 1.
Parameters:
Code example:
var someDate = new tizen.TZDate(1999, 11, 31, 23, 59, 59, 999, "Europe/London");
someDate.setDate(1); // Changes the day of month to 1.
console.log(someDate.getDate()); // should output 1.
getDay
long getDay();
Since: 2.4
Return value:
long The day of the weekCode example:
var someDate = new tizen.TZDate(1999, 11, 31, 23, 59, 59, 999, "Europe/London");
console.log(someDate.getDay()); // should output "5", because 31st of December 1999 was friday.
getFullYear
long getFullYear();
Since: 2.4
Positive values indicate AD(Anno Domini) years. 0 and negative values indicate BC(Before Christ) years. For example, 1 = AD 1, 0 = BC 1, -1 = BC 2.
Return value:
long The yearCode example:
var someDate = new tizen.TZDate(1999, 11, 31, 23, 59, 59, 999, "Europe/London");
console.log(someDate.getFullYear()); // should output 1999.
setFullYear
void setFullYear(long year);
Since: 2.4
Parameters:
Code example:
var someDate = new tizen.TZDate(1999, 11, 31, 23, 59, 59, 999, "Europe/London");
someDate.setFullYear(2099); // Changes the year to 2099.
console.log(someDate.getFullYear()); // should output 2099.
getHours
long getHours();
Since: 2.4
Return value:
long The hourCode example:
var someDate = new tizen.TZDate(1999, 11, 31, 23, 59, 59, 999, "Europe/London");
console.log(someDate.getHours()); // should output 23.
setHours
void setHours(long hours);
Since: 2.4
If the value passed as a parameter is greater than 23 or smaller than 0, the TZDate will be automatically recalculated to reflect this. For example, calling setHours(24) results in setting hour to 00:00 and date to the next day.
Parameters:
Code example:
var someDate = new tizen.TZDate(1999, 11, 31, 23, 59, 59, 999, "Europe/London");
someDate.setHours(15); // Sets the hour to 3 PM.
console.log(someDate.getHours()); // should output 15.
getMilliseconds
long getMilliseconds();
Since: 2.4
Return value:
long The millisecondsCode example:
var someDate = new tizen.TZDate(1999, 11, 31, 23, 59, 59, 999, "Europe/London");
console.log(someDate.getMilliseconds()); // should output 999.
setMilliseconds
void setMilliseconds(long ms);
Since: 2.4
If it tries to set the millisecond bigger than 999 or smaller than 0, it will be calculated automatically. For example, if ms is 1000, it will set the milliseconds to 0 and add a second.
Parameters:
Code example:
var someDate = new tizen.TZDate(1999, 11, 31, 23, 59, 59, 999, "Europe/London");
someDate.setMilliseconds(42);
console.log(someDate.getMilliseconds()); // should output 42.
getMinutes
long getMinutes();
Since: 2.4
Return value:
long The minutesCode example:
var someDate = new tizen.TZDate(1999, 11, 31, 23, 59, 59, 999, "Europe/London");
console.log(someDate.getMinutes()); // Output 59.
setMinutes
void setMinutes(long minutes);
Since: 2.4
If the value passed as a parameter is greater than 59 or smaller than 0, the TZDate will be automatically recalculated to reflect this. For example, calling setMinutes(60) results in setting minutes to 0 and adding one hour.
Parameters:
Code example:
var someDate = new tizen.TZDate(1999, 11, 31, 23, 59, 59, 999, "Europe/London");
someDate.setMinutes(58);
console.log(someDate.getMinutes()); // should output 58.
getMonth
long getMonth();
Since: 2.4
Return value:
long The monthCode example:
var someDate = new tizen.TZDate(1999, 11, 31, 23, 59, 59, 999, "Europe/London");
console.log(someDate.getMonth()); // should output 11.
setMonth
void setMonth(long month);
Since: 2.4
If the value passed as a parameter is greater than 11 or smaller than 0, the TZDate will be automatically recalculated to reflect this. For example, calling setMonth(12) results in setting month to 0 and adding one year.
Parameters:
Code example:
var someDate = new tizen.TZDate(1999, 11, 31, 23, 59, 59, 999, "Europe/London");
someDate.setMonth(2); /* Changes the month to March */
console.log(someDate.getMonth()); /* Outputs 2 */
getSeconds
long getSeconds();
Since: 2.4
Return value:
long The secondsCode example:
var someDate = new tizen.TZDate(1999, 11, 31, 23, 59, 59, 999, "Europe/London");
console.log(someDate.getSeconds()); // Outputs 59
setSeconds
void setSeconds(long seconds);
Since: 2.4
If the value passed as a parameter is greater than 59 or smaller than 0, the TZDate will be automatically recalculated to reflect this. For example, calling setSeconds(60) results in setting seconds to 0 and adding one minute.
Parameters:
Code example:
var someDate = new tizen.TZDate(1999, 11, 31, 23, 59, 59, 999, "Europe/London");
someDate.setSeconds(23);
console.log(someDate.getSeconds()); // Outputs 23
getUTCDate
long getUTCDate();
Since: 2.4
Return value:
long The day of the month, according to universal timeCode example:
var someDate = new tizen.TZDate(1999, 11, 31, 23, 59, 59, 999, "Europe/London");
console.log(someDate.getUTCDate()); // should output 31.
setUTCDate
void setUTCDate(long date);
Since: 2.4
If the value passed as a parameter is greater than the last day of current month or smaller than 0, the TZDate will be automatically recalculated to reflect this. For example, calling setUTCDate(32) when TZDate's month is May results in setting it to June 1.
Parameters:
Code example:
var someDate = new tizen.TZDate(1999, 11, 31, 23, 59, 59, 999, "Europe/London");
someDate.setUTCDate(5) // Change the day of month to 5th.
console.log(someDate.getUTCDate()); // should output 5.
getUTCDay
long getUTCDay();
Since: 2.4
Return value:
long The day of the week, according to universal timeCode example:
var someDate = new tizen.TZDate(1999, 11, 31, 23, 59, 59, 999, "Europe/London");
console.log(someDate.getUTCDay()); // Outputs 5, since 31st of December 1999 was Friday
getUTCFullYear
long getUTCFullYear();
Since: 2.4
Positive values indicate AD(Anno Domini) years. 0 and negative values indicate BC(Before Christ) years. For example, 1 = AD 1, 0 = BC 1, -1 = BC 2.
Return value:
long The year, according to universal timeCode example:
var someDate = new tizen.TZDate(1999, 11, 31, 23, 59, 59, 999, "Europe/London");
console.log(someDate.getUTCFullYear()); // Outputs 1999
setUTCFullYear
void setUTCFullYear(long year);
Since: 2.4
Parameters:
Code example:
var someDate = new tizen.TZDate(1999, 11, 31, 23, 59, 59, 999, "Europe/London");
someDate.setUTCFullYear(2099); // Change the year to 2099, universal time.
console.log(someDate.getUTCFullYear()); // should output 2099.
getUTCHours
long getUTCHours();
Since: 2.4
Return value:
long The hour, according to universal timeCode example:
var someDate = new tizen.TZDate(1999, 11, 31, 23, 59, 59, 999, "Europe/London");
console.log(someDate.getUTCHours()); // Outputs 23
setUTCHours
void setUTCHours(long hours);
Since: 2.4
If the value passed as a parameter is greater than 23 or smaller than 0, the TZDate will be automatically recalculated to reflect this. For example, calling setUTCHours(24) results in setting hour to 0 and adding one day.
Parameters:
Code example:
var someDate = new tizen.TZDate(1999, 11, 31, 23, 59, 59, 999, "Europe/London");
someDate.setUTCHours(15);
console.log(someDate.getUTCHours()); // should output 15.
getUTCMilliseconds
long getUTCMilliseconds();
Since: 2.4
Return value:
long The milliseconds, according to universal timeCode example:
var someDate = new tizen.TZDate(1999, 11, 31, 23, 59, 59, 999, "Europe/London");
console.log(someDate.getUTCMilliseconds()); // Outputs 999
setUTCMilliseconds
void setUTCMilliseconds(long ms);
Since: 2.4
If the value passed as a parameter is greater than 999 or smaller than 0, the TZDate will be automatically recalculated to reflect this. For example, calling setUTCMilliseconds(1000) results in setting milliseconds to 0 and adding one second.
Parameters:
Code example:
var someDate = new tizen.TZDate(1999, 11, 31, 23, 59, 59, 999, "Europe/London");
someDate.setUTCMillisecond(42);
console.log(someDate.getUTCMilliseconds()); // Outputs 42
getUTCMinutes
long getUTCMinutes();
Since: 2.4
Return value:
long The minutes, according to universal timeCode example:
var someDate = new tizen.TZDate(1999, 11, 31, 23, 59, 59, 999, "Europe/London");
console.log(someDate.getUTCMinutes()); // Outputs 59
setUTCMinutes
void setUTCMinutes(long minutes);
Since: 2.4
If the value passed as a parameter is greater than 59 or smaller than 0, the TZDate will be automatically recalculated to reflect this. For example, calling setUTCMinutes(60) results in setting minutes to 0 and adding one hour.
Parameters:
Code example:
var someDate = new tizen.TZDate(1999, 11, 31, 23, 59, 59, 999, "Europe/London");
someDate.setUTCMinutes(58);
console.log(someDate.getUTCMinutes()); // Outputs 58
getUTCMonth
long getUTCMonth();
Since: 2.4
Return value:
long The month, according to universal timeCode example:
var someDate = new tizen.TZDate(1999, 11, 31, 23, 59, 59, 999, "Europe/London");
console.log(someDate.getUTCMonth()); // should output 11.
setUTCMonth
void setUTCMonth(long month);
Since: 2.4
If the value passed as a parameter is greater than 11 or smaller than 0, the TZDate will be automatically recalculated to reflect this. For example, calling setUTCMonth(12) results in setting month to 0 and adding one year.
Parameters:
Code example:
var someDate = new tizen.TZDate(1999, 11, 31, 23, 59, 59, 999, "Europe/London");
someDate.setUTCMonth(2); // Sets the month to March, according to the universal time.
console.log(someDate.getUTCMonth()); // should output 2.
getUTCSeconds
long getUTCSeconds();
Since: 2.4
Return value:
long The seconds, according to universal timeCode example:
var someDate = new tizen.TZDate(1999, 11, 31, 23, 59, 59, 999, "Europe/London");
console.log(someDate.getUTCSeconds()); // should output 59.
setUTCSeconds
void setUTCSeconds(long seconds);
Since: 2.4
If the value passed as a parameter is greater than 59 or smaller than 0, the TZDate will be automatically recalculated to reflect this. For example, calling setUTCSeconds(60) results in setting seconds to 0 and adding one minute.
Parameters:
Code example:
var someDate = new tizen.TZDate(1999, 11, 31, 23, 59, 59, 999, "Europe/London");
someDate.setUTCSeconds(23);
console.log(someDate.getUTCSeconds()); // Outputs 23
getTimezone
DOMString getTimezone();
Since: 2.4
Zero or more slashes separate different components, with the most general descriptor first and the most specific one last. For example, 'Europe/Berlin', 'America/Argentina/Buenos_Aires'.
This attribute uniquely identifies the timezone.
Return value:
DOMString The string timezone identifierCode example:
var someDate = new tizen.TZDate(1999, 11, 31, 23, 59, 59, 999, "Europe/London");
console.log(someDate.getTimezone());
Output example:
Europe/London
toTimezone
TZDate toTimezone(DOMString tzid);
Since: 2.4
Parameters:
Return value:
TZDate The new TZDate in given TimezoneExceptions:
with error type TypeMismatchError, if the input parameter is not compatible with the expected type for that parameter.
with error type InvalidValuesError, if the provided TZID is not recognized as a valid timezone identifier.
with error type UnknownError, if the call failed due to an unknown error.
Code example:
var someDate = new tizen.TZDate(1999, 11, 31, 23, 59, 59, 999, "Europe/London");
var koreanDate = someDate.toTimezone("Asia/Seoul");
console.log(someDate.toString());
Output example:
Saturday, January 1, 2000, 8:59:59 AM GMT+0900 South Korea Time
toLocalTimezone
TZDate toLocalTimezone();
Since: 2.4
Return value:
TZDate The new TZDate in local TimezoneExceptions:
with error type UnknownError, if the call failed due to an unknown error.
Code example:
// This example assumes that the device's local time zone is set to Asia/Seoul.
// You may get different results depending on your local time zone settings.
var someDate = new tizen.TZDate(1999, 11, 31, 23, 59, 59, 999, "Europe/London");
var localDate = someDate.toLocalTimezone();
console.log(localDate.toString());
Output example:
Saturday, January 1, 2000, 8:59:59 AM GMT+0900 South Korea Time
toUTC
TZDate toUTC();
Since: 2.4
Return value:
TZDate The Date/Time in UTCExceptions:
with error type UnknownError, if the call failed due to an unknown error.
Code example:
var someDate = new tizen.TZDate(1999, 11, 31, 23, 59, 59, 999, "Asia/Seoul");
var utcDate = someDate.toUTC();
console.log(utcDate.toString());
Output example:
Friday, December 31, 1999, 2:59:59 PM GMT+0000 GMT
difference
TimeDuration difference(TZDate other);
Since: 2.4
Calculates the difference in time between this and the other object. This comparison method takes timezones into consideration for the comparison.
The TimeDuration that is returned is effectively this - other. The return value is a duration in milliseconds both TZDate objects have a time component, in days, otherwise. The result value will be:
Parameters:
Return value:
TimeDuration The duration in milliseconds between the two date/time objects (or in days for comparison between dates with no time component)Exceptions:
with error type TypeMismatchError, if the input parameter is not compatible with the expected type for that parameter.
with error type UnknownError, if the call failed due to an unknown error.
Code example:
// Prepares two TZDates pointing at new year eves in 2011 and 2012, respectively:
var newYearEve2011 = new tizen.TZDate(2011, 0, 0, 0, 0, 0, 0, "Europe/London");
var newYearEve2012 = new tizen.TZDate(2012, 0, 0, 0, 0, 0, 0, "Europe/London");
// Calculates how much is the difference between those two dates:
var difference = newYearEve2012.difference(newYearEve2011);
console.log("The difference is " + difference.length + " " + difference.unit);
Output example (since none of those dates have time component):
The difference is 365 DAYS
Code example:
// Prepares two TZDates pointing at 6:00 PM and 8:00 PM on the same day:
var joggingStart = new tizen.TZDate(2015, 6, 6, 18, 0, 0, 0, "Europe/London");
var joggingEnd = new tizen.TZDate(2015, 6, 6, 20, 0, 0, 0, "Europe/London");
// Calculates how much is the difference between those two dates:
var difference = joggingEnd.difference(joggingStart);
console.log("The difference is " + difference.length + " " + difference.unit);
Output example (since both of those dates do have time component):
The difference is 7200000 MSECS
equalsTo
boolean equalsTo(TZDate other);
Since: 2.4
This method takes the timezones into consideration and will return true if the two TZDate objects represent the same instant in different timezones.
Parameters:
Return value:
boolean true if the 2 date/times are the sameExceptions:
with error type TypeMismatchError, if the input parameter is not compatible with the expected type for that parameter.
with error type UnknownError, if the call failed due to an unknown error.
Code example:
var noonInEngland = new tizen.TZDate(2016, 0, 27, 12, 0, 0, 0, 'Europe/London');
var sameTimeInKorea = noonInEngland.toTimezone('Asia/Seoul');
var isTheSame = noonInEngland.equalsTo(sameTimeInKorea);
// Those are the same dates (in different time zones), so the output should be "Those dates are equal."
if(isTheSame) {
console.log("Those dates are equal.");
} else {
console.log("Those dates are not equal.");
}
Code example:
var noonInEngland = new tizen.TZDate(2016, 0, 27, 12, 0, 0, 0, 'Europe/London');
var noonInKorea = new tizen.TZDate(2016, 0, 27, 12, 0, 0, 0, 'Asia/Seoul');
var isTheSame = noonInEngland.equalsTo(noonInKorea);
// Those are not the same dates (obviously, noon in London is not noon in Seoul),
// so the output should be "Those dates are not equal."
if(isTheSame) {
console.log("Those dates are equal.");
} else {
console.log("Those dates are not equal.");
}
earlierThan
boolean earlierThan(TZDate other);
Since: 2.4
This method takes the timezones into consideration.
Parameters:
Return value:
boolean true, if the Date/Time is earlier than the one passed in argumentExceptions:
with error type TypeMismatchError, if the input parameter is not compatible with the expected type for that parameter.
with error type UnknownError, if the call failed due to an unknown error.
Code example:
// Create a new TZDate object pointing to noon in London:
var tzd1 = new tizen.TZDate(2016, 0, 1, 12, 0, 0, 0, 'Europe/London');
// Create a new TZDate object pointing to 6 PM in Seoul on the same day:
var tzd2 = new tizen.TZDate(2016, 0, 1, 18, 0, 0, 0, 'Asia/Seoul');
// is 12:00 local time in London earlier than 18:00 local time in Seoul?
var isEarlier = tzd1.earlierThan(tzd2);
// should output 'false', since local time in Seoul is GMT (London) + 9 hours.
console.log(isEarlier);
laterThan
boolean laterThan(TZDate other);
Since: 2.4
This method takes the timezones into consideration.
Parameters:
Return value:
boolean true, if the Date/Time is later than the one passed in argumentExceptions:
with error type TypeMismatchError, if the input parameter is not compatible with the expected type for that parameter.
with error type UnknownError, if the call failed due to an unknown error.
Code example:
// Create a new TZDate object pointing to noon in London:
var tzd1 = new tizen.TZDate(2016, 0, 1, 12, 0, 0, 0, 'Europe/London');
// Create a new TZDate object pointing to 6 PM in Seoul on the same day:
var tzd2 = new tizen.TZDate(2016, 0, 1, 18, 0, 0, 0, 'Asia/Seoul');
// Is 12:00 local time in London earlier than 18:00 local time in Seoul?
var isLater = tzd1.laterThan(tzd2);
// Outputs "true", since local time in Seoul is GMT (London) + 9 hours.
console.log(isLater);
addDuration
TZDate addDuration(TimeDuration duration);
Since: 2.4
If the length of duration is negative, the new date/time will be earlier than it used to.
Note that calling this method does not alter the current object.
Parameters:
Return value:
TZDate The new TZDate by adding a durationExceptions:
with error type TypeMismatchError, if the input parameter is not compatible with the expected type for that parameter.
with error type UnknownError, if the call failed due to an unknown error.
Code example:
var now = tizen.time.getCurrentDateTime();
var in_one_week = now.addDuration(new tizen.TimeDuration(7, "DAYS"));
toLocaleDateString
DOMString toLocaleDateString();
Since: 2.4
Return value:
DOMString The date portion of the TZDate object as a string, using locale conventionsCode example:
var someDate = new tizen.TZDate(1999, 11, 31, 23, 59, 59, 999, 'Europe/London');
console.log(someDate.toLocaleDateString());
Output example (depending on locale settings):
Friday, December 31, 1999
toLocaleTimeString
DOMString toLocaleTimeString();
Since: 2.4
Return value:
DOMString The time portion of the TZDate object as a string, using locale conventionsCode example:
var someDate = new tizen.TZDate(1999, 11, 31, 23, 59, 59, 999, 'Europe/London');
console.log(someDate.toLocaleTimeString());
Output example (depending on locale settings):
11:59:59 PM
toLocaleString
DOMString toLocaleString();
Since: 2.4
Return value:
DOMString The string representation of the TZDate object, using locale conventionsCode example:
var someDate = new tizen.TZDate(1999, 11, 31, 23, 59, 59, 999, 'Europe/London');
console.log(someDate.toLocaleString());
Output example (depending on locale settings):
Friday, December 31, 1999, 11:59:59 PM
toDateString
DOMString toDateString();
Since: 2.4
Return value:
DOMString The date portion of the TZDate object as a stringCode example:
var someDate = new tizen.TZDate(1999, 11, 31, 23, 59, 59, 999, 'Europe/London');
// Should output: "Friday, December 31, 1999"
console.log(someDate.toDateString());
toTimeString
DOMString toTimeString();
Since: 2.4
Return value:
DOMString The time portion of the TZDate object as a stringCode example:
var someDate = new tizen.TZDate(1999, 11, 31, 23, 59, 59, 999, 'Europe/London');
// Should output: "11:59:59 PM GMT+0000 United Kingdom Time"
console.log(someDate.toTimeString());
toString
DOMString toString();
Since: 2.4
Return value:
DOMString The string representation of the TZDate objectCode example:
var someDate = new tizen.TZDate(1999, 11, 31, 23, 59, 59, 999, 'Europe/London');
// Output: "Friday, December 31, 1999, 11:59:59 PM GMT+0000 United Kingdom Time"
console.log(someDate.toString());
getTimezoneAbbreviation
Deprecated. Deprecated since 2.4.
DOMString getTimezoneAbbreviation();
Since: 2.4
For example, in Toronto this is currently "EST" during the winter months and "EDT" during the summer months when daylight savings time is in effect.
Return value:
DOMString The abbreviation of the time zone (such as "EST")Exceptions:
with error type UnknownError, if the call failed due to an unknown error.
Code example:
// The following code uses DEPRECATED methods.
// please do not use this in new applications.
var abbreviation = tizen.time.getCurrentDateTime().getTimezoneAbbreviation();
console.log("The time zone abbreviation is: " + abbreviation);
// Example output:
// The time zone abbreviation is: GMT+09:00
secondsFromUTC
long secondsFromUTC();
Since: 2.4
Returns the offset (in seconds) from UTC of the timezone, accounting for daylight savings if it is in the timezone. For example, if time zone is GMT+8, it will return -32,400.
Return value:
long The offset from UTC in secondsExceptions:
with error type UnknownError, if the call failed due to an unknown error.
Code example:
var offset = tizen.time.getCurrentDateTime().secondsFromUTC();
var myDate = new Date();
var exp_offset = myDate.getTimezoneOffset()*60;
//offset is equals to exp_offset.
isDST
boolean isDST();
Since: 2.4
Indicates if daylight savings are in effect for the time zone and instant identified by the TZDate object.
Return value:
boolean The flag indicating whether the daylight saving are in effectExceptions:
with error type UnknownError, if the call failed due to an unknown error.
Code example:
var summertime = new tizen.TZDate(2015, 6, 1, 10, 0, 0, 0, 'Europe/London');
var wintertime = new tizen.TZDate(2015, 0, 1, 10, 0, 0, 0, 'Europe/London');
var isDstActiveInSummer = summertime.isDST(); // true
var isDstActiveInWinter = wintertime.isDST(); // false
getPreviousDSTTransition
TZDate? getPreviousDSTTransition();
Since: 2.4
Return value:
TZDate The date of the previous daylight saving transition (before the instant identified by the TZDate)Exceptions:
with error type UnknownError, if the call failed due to an unknown error.
Code example:
// Creates the TZDate object pointing to January 2016.
var winter16 = new tizen.TZDate(2016, 0, 1, 10, 0, 0, 0, 'Europe/London');
// Gets the date of previous DST transition:
var previousDstTransition = winter16.getPreviousDSTTransition();
// Should output: "Sunday, October 25, 2015, 1:00:00 AM GMT+0000 United Kingdom Time"
console.log(previousDstTransition.toString());
getNextDSTTransition
TZDate? getNextDSTTransition();
Since: 2.4
Return value:
TZDate The date of the next daylight saving transition (after the instant identified by the TZDate)Exceptions:
with error type UnknownError, if the call failed due to an unknown error.
Code example:
// Creates the TZDate object pointing to January 2016.
var winter16 = new tizen.TZDate(2016, 0, 1, 10, 0, 0, 0, 'Europe/London');
// Gets the date of next DST transition:
var nextDstTransition = winter16.getNextDSTTransition();
// Should output: "Sunday, March 27, 2016, 2:00:00 AM GMT+0100 United Kingdom Time"
console.log(nextDstTransition.toString());
[Constructor(long long length, optional TimeDurationUnit? unit)]
interface TimeDuration
{
attribute long long length;
attribute TimeDurationUnit unit;
TimeDuration difference(TimeDuration other) raises(WebAPIException);
boolean equalsTo(TimeDuration other) raises(WebAPIException);
boolean lessThan(TimeDuration other) raises(WebAPIException);
boolean greaterThan(TimeDuration other) raises(WebAPIException);
};
Since: 2.4
TimeDuration(long long length, optional TimeDurationUnit? unit);
Code example:
var now = tizen.time.getCurrentDateTime();
var tomorrow = now.addDuration(new tizen.TimeDuration(1, "DAYS")); // Becomes tomorrow, same time.
The unit of the duration length (milliseconds, seconds, minutes, hours, or days) is determined by the duration unit attribute.
Since: 2.4
The default value is "MSECS" (milliseconds unit).
Since: 2.4
Code example:
// Changing both length and unit of existing TimeDuration objects is possible:
var now = tizen.time.getCurrentDateTime();
var threeHours = new tizen.TimeDuration();
threeHours.length = 3;
threeHours.unit = "HOURS";
var later = now.addDuration(threeHours); // later points to a time three hours from now.
difference
TimeDuration difference(TimeDuration other);
Since: 2.4
Calculates the difference in time between this and other. The TimeDuration that is returned is effectively first - other (that is: positive if the first parameter is larger).
The returned TimeDuration is the biggest possible unit without losing the precision.
Parameters:
Return value:
The new TimeDuration object corresponding to the result of this - other.Exceptions:
with error type TypeMismatchError, if the input parameter is not compatible with the expected type for that parameter.
with error type UnknownError, if the call failed due to an unknown error.
Code example:
// Assume that event1 and event2 are tizen.CalendarEvent objects.
// Computes event1.duration - event2.duration
var diff = event1.duration.difference(event2.duration);
if (diff.length > 0)
console.log("The event1 is longer than event2.");
else if (diff.length == 0)
console.log("The duration of two events is same.");
else
console.log("The event1 is shorter than the event2.");
equalsTo
boolean equalsTo(TimeDuration other);
Since: 2.4
This method takes the units into consideration and will return true if the two TimeDuration objects represent the same duration in different units.
Parameters:
Return value:
boolean true if the two TimeDuration object represent the same durationExceptions:
with error type TypeMismatchError, if the input parameter is not compatible with the expected type for that parameter.
with error type UnknownError, if the call failed due to an unknown error.
Code example:
var d1 = new tizen.TimeDuration(60, "MINS"); // 60 minutes
var d2 = new tizen.TimeDuration(1, "HOURS"); // 1 hour
var ret = d1.equalsTo(d2); // Returns true
lessThan
boolean lessThan(TimeDuration other);
Since: 2.4
This method takes the units into consideration when doing the comparison.
Parameters:
Return value:
boolean true if the TimeDuration is less than otherExceptions:
with error type TypeMismatchError, if the input parameter is not compatible with the expected type for that parameter.
with error type UnknownError, if the call failed due to an unknown error.
Code example:
var d1 = new tizen.TimeDuration(1, "HOURS"); // 1 hour
var d2 = new tizen.TimeDuration(120, "MINS"); // 120 minutes
var ret = d1.lessThan(d2); // Returns true
greaterThan
boolean greaterThan(TimeDuration other);
Since: 2.4
This method takes the units into consideration when doing the comparison.
Parameters:
Return value:
boolean true if the TimeDuration is greater than otherExceptions:
with error type TypeMismatchError, if the input parameter is not compatible with the expected type for that parameter.
with error type UnknownError, if the call failed due to an unknown error.
Code example:
var d1 = new tizen.TimeDuration(120, "MINS"); // 120 minutes
var d2 = new tizen.TimeDuration(1, "HOURS"); // 1 hour
var ret = d1.greaterThan(d2); // Returns true
module Time {
enum TimeDurationUnit { "MSECS", "SECS", "MINS", "HOURS", "DAYS" };
[NoInterfaceObject] interface TimeManagerObject {
readonly attribute TimeUtil time;
};
Tizen implements TimeManagerObject;
[NoInterfaceObject] interface TimeUtil {
TZDate getCurrentDateTime() raises(WebAPIException);
DOMString getLocalTimezone() raises(WebAPIException);
DOMString[] getAvailableTimezones() raises(WebAPIException);
DOMString getDateFormat(optional boolean? shortformat) raises(WebAPIException);
DOMString getTimeFormat() raises(WebAPIException);
boolean isLeapYear(long year) raises(WebAPIException);
void setDateTimeChangeListener(SuccessCallback changeCallback) raises(WebAPIException);
void unsetDateTimeChangeListener() raises(WebAPIException);
void setTimezoneChangeListener(SuccessCallback changeCallback) raises(WebAPIException);
void unsetTimezoneChangeListener() raises(WebAPIException);
};
[Constructor(optional Date? datetime, optional DOMString? timezone),
Constructor(long year, long month, long day, optional long? hours, optional long? minutes, optional long? seconds, optional long? milliseconds, optional DOMString? timezone)]
interface TZDate {
long getDate();
void setDate(long date);
long getDay();
long getFullYear();
void setFullYear(long year);
long getHours();
void setHours(long hours);
long getMilliseconds();
void setMilliseconds(long ms);
long getMinutes();
void setMinutes(long minutes);
long getMonth();
void setMonth(long month);
long getSeconds();
void setSeconds(long seconds);
long getUTCDate();
void setUTCDate(long date);
long getUTCDay();
long getUTCFullYear();
void setUTCFullYear(long year);
long getUTCHours();
void setUTCHours(long hours);
long getUTCMilliseconds();
void setUTCMilliseconds(long ms);
long getUTCMinutes();
void setUTCMinutes(long minutes);
long getUTCMonth();
void setUTCMonth(long month);
long getUTCSeconds();
void setUTCSeconds(long seconds);
DOMString getTimezone();
TZDate toTimezone(DOMString tzid) raises(WebAPIException);
TZDate toLocalTimezone() raises(WebAPIException);
TZDate toUTC() raises(WebAPIException);
TimeDuration difference(TZDate other) raises(WebAPIException);
boolean equalsTo(TZDate other) raises(WebAPIException);
boolean earlierThan(TZDate other) raises(WebAPIException);
boolean laterThan(TZDate other) raises(WebAPIException);
TZDate addDuration(TimeDuration duration) raises(WebAPIException);
DOMString toLocaleDateString();
DOMString toLocaleTimeString();
DOMString toLocaleString();
DOMString toDateString();
DOMString toTimeString();
DOMString toString();
long secondsFromUTC() raises(WebAPIException);
boolean isDST() raises(WebAPIException);
TZDate? getPreviousDSTTransition() raises(WebAPIException);
TZDate? getNextDSTTransition() raises(WebAPIException);
};
[Constructor(long long length, optional TimeDurationUnit? unit)]
interface TimeDuration
{
attribute long long length;
attribute TimeDurationUnit unit;
TimeDuration difference(TimeDuration other) raises(WebAPIException);
boolean equalsTo(TimeDuration other) raises(WebAPIException);
boolean lessThan(TimeDuration other) raises(WebAPIException);
boolean greaterThan(TimeDuration other) raises(WebAPIException);
};
};