Demo - Formatting Dates and Numbers
HTML
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
<link rel="stylesheet" href="https://cdn.grapecity.com/wijmo/5.latest/styles/wijmo.min.css">
<script src="https://cdn.grapecity.com/wijmo/5.latest/controls/wijmo.min.js"></script>
<script src="https://cdn.grapecity.com/wijmo/5.latest/controls/wijmo.input.min.js"></script>
<div class="container">
<h1>
Formatting Dates and Numbers</h1>
<p>
To globalize your Wijmo application, include a reference to
the appropriate culture file after loading Wijmo.
<a href="https://wijmo.com/5/docs/static/globalization.html" target="_blank">
Wijmo includes over 45 culture files you can choose from.
</a></p>
<label>
Please Select a Culture
<div id="theCulture">
</div>
</label>
<h2>
Dates</h2>
<p>
Dates are formatted using the
<b>Globalize.formatDate</b> function.
The format strings are described here:
<a href="https://wijmo.com/5/docs/topic/wijmo.Globalize.Class.html#formatDate" target="_blank" >
Date and Time Format Strings
</a></p>
<table id="tblDates" class="table table-condensed">
<thead>
<th>format</th>
<th>description</th>
<th>result</th>
</thead>
<tbody>
<tr>
<td><b>d</b></td>
<td>Short Date Pattern</td>
<td>xx</td>
</tr>
<tr>
<td><b>D</b></td>
<td>Long Date Pattern</td>
<td>xx</td>
</tr>
<tr>
<td><b>f</b></td>
<td>Full Date/Time Pattern (short time)</td>
<td>xx</td>
</tr>
<tr>
<td><b>F</b></td>
<td>Full Date/Time Pattern (long time)</td>
<td>xx</td>
</tr>
<tr>
<td><b>t</b></td>
<td>Short Time Pattern</td>
<td>xx</td>
</tr>
<tr>
<td><b>T</b></td>
<td>Long Time Pattern</td>
<td>xx</td>
</tr>
<tr>
<td><b>'Q'Q yyyy</b></td>
...
JavaScript
onload = function() {
// select culture
var theCulture = new wijmo.input.ComboBox('#theCulture', {
displayMemberPath: 'name',
itemsSource: [
{ name: 'English', key: 'en' },
{ name: 'Spanish', key: 'es' },
{ name: 'Italian', key: 'it' },
{ name: 'French', key: 'fr' },
{ name: 'German', key: 'de' },
{ name: 'Dutch', key: 'nl' },
{ name: 'Japanese', key: 'ja' },
{ name: 'Korean', key: 'ko' },
{ name: 'Chinese', key: 'zh-HK' },
],
selectedIndexChanged: function(s, e) {
// get culture url
var url = 'https://cdn.grapecity.com/wijmo/5.latest/controls/cultures/wijmo.culture.' +
s.selectedItem.key +
'.min.js';
// apply new culture to page
var scripts = document.getElementsByTagName('script'),
script;
for (var i = 0; i < scripts.length; i++) {
script = scripts[i];
if (script.src.indexOf('/cultures/wijmo.culture.') > -1) {
script.parentElement.removeChild(script);
break;
}
}
script = document.createElement('script');
script.onload = updateTables;
script.src = url;
document.head.appendChild(script);
}
});
// initialize value and precision
var theValue = new wijmo.input.InputNumber('#theValue', {
value: 1234.5678,
step: 1,
valueChanged: updateTables
});
var thePrecision = new wijmo.input.InputNumber('#thePrecision', {
value: 2,
step: 1,
min: 0,
max: 10,
valueChanged: updateTables
});
// update the tables
updateTables();
function updateTables() {
var rows, cells, fmt, prec;
// update dates
var theDate = new Date();
rows = document.body.querySelectorAll('#tblDates tbody tr');
for (var i = 0; i < rows.length; i++) {
cells = rows[i].children;
fmt = cells[0].textContent;
cells[2].textContent = wijmo.Globalize.format(theDate, fmt);
}
// update numbers
rows = document.body.querySelectorAll('#tblNumbers tbody tr');
for (var...