- Accelerometer
- Camera
- Capture
- Compass
- Connection
- Contacts
- Device
- Events
- File
- Geolocation
- Globalization
- InAppBrowser
- Media
- Notification
- Splashscreen
- Storage
- Getting Started Guides
- Command-Line Usage
- Privacy Guide
- Upgrading Guides
- Project Settings
- Plugin Development Guide
- Domain Whitelist Guide
- Embedding WebView
globalization.getDateNames
Returns an array of either the names of the months or days of the week according to the client's user preferences and calendar.
navigator.globalization.getDateNames(successCB, errorCB, options);
Description
It returns the array of names to the successCB callback with a properties object as a parameter. That object should have a value
property with an Array of Strings. That array will be the names starting from either the first month in the year or the first day of the week, depending on the option selected.
If there is an error obtaining the names, then the errorCB callback is invoked with a GlobalizationError object as a parameter. The expected code for this error is GlobalizationError.UNKNOWN_ERROR.
options.type
can be 'narrow', or 'wide'.
options.item
can be 'months', or 'days'.
The default options are {type:'wide', item:'months'}
.
The options parameter is optional.
Supported Platforms
- Android
- BlackBerry WebWorks (OS 5.0 and higher)
- iPhone
- Windows Phone 8
Quick Example
In the case when the browser is set to the en_US locale, this should display a series of 12 popup dialogs, one per month, with text similar to "month: January"
navigator.globalization.getDateNames(
function (names) {
for (var i=0; i<names.value.length; i++) {
alert('month: ' + names.value[i] + '\n');
}
},
function () {alert('Error getting names\n');},
{type:'wide', item:'months'}
);
Full Example
<!DOCTYPE HTML>
<html>
<head>
<title>Cordova</title>
<script type="text/javascript" charset="utf-8" src="cordova-x.x.x.js"></script>
<script type="text/javascript" charset="utf-8">
function checkDateNames() {
navigator.globalization.getDateNames(
function (names) {
for (var i=0; i<names.value.length; i++) {
alert('month: ' + names.value[i] + '\n');
}
},
function () {alert('Error getting names\n');},
{type:'wide', item:'months'}
);
}
</script>
</head>
<body>
<button onclick="checkDateNames()">Click for date names</button>
</body>
</html>