Parsing Dates and Numbers

To globalize your application, register the appropriate culture while registering the C1 MVC scripts. Wijmo includes over 40 culture files you can choose from.

Dates

Dates are parsed using the Globalize.parseDate function. The format strings are the same used to format dates. For details regarding format strings, please refer the online documentation.

Try it yourself with the help of the sample below:


Numbers

Numbers are parsed using the Globalize.parseFloat function. The format strings are the same used to format numbers. For details regarding format strings, please refer the online documentation.

Try it yourself with the help of the sample below:


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
// This file locates: "Scripts/Lesson/C1Mvc/Parsing.js".
c1.documentReady(function () {
    // parse dates
    document.getElementById('dtBtn').addEventListener('click', function () {
        var text = document.getElementById('dtIn').value;
        var fmt = document.getElementById('dtFmt').value;
        var value = wijmo.Globalize.parseDate(text, fmt);
        var output = document.getElementById('dtOutput');
        if (wijmo.isDate(value)) {
            output.textContent = 'Parsed OK: ' + wijmo.Globalize.format(value, fmt);
        } else {
            output.textContent = '** Could not parse date... **';
        }
    });
 
    // parse numbers
    document.getElementById('numBtn').addEventListener('click', function () {
        var text = document.getElementById('numIn').value;
        var fmt = document.getElementById('numFmt').value;
        var value = wijmo.Globalize.parseFloat(text, fmt);
        var output = document.getElementById('numOutput');
        if (wijmo.isNumber(value)) {
            output.textContent = 'Parsed OK: ' + wijmo.Globalize.format(value, fmt);
        } else {
            output.textContent = '** Could not parse number... **';
        }
    });
});
1
2
3
4
5
6
7
8
9
10
11
12
13
using System.Web.Mvc;
 
namespace LearnMvcClient.Controllers
{
    public partial class C1MvcController : Controller
    {
        // GET: Parsing
        public ActionResult Parsing()
        {
            return View();
        }
    }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<h1>
    @Html.Raw(Resources.C1Mvc.Parsing_Title)
</h1>
<p>
    @Html.Raw(Resources.C1Mvc.Parsing_Text1)
</p>
 
<label>
    @Html.Raw(Resources.C1Mvc.Parsing_Text2)
    @Html.Partial("_CultureSelector")
</label>
 
<h2>
    @Html.Raw(Resources.C1Mvc.Parsing_Title1)
</h2>
<p>
    @Html.Raw(Resources.C1Mvc.Parsing_Text3)
</p>
 
<p>
    @Html.Raw(Resources.C1Mvc.Parsing_Text4)
</p>
<label>
    @Html.Raw(Resources.C1Mvc.Parsing_Text5)
    <input id="dtFmt" value="d">
</label>
<label>
    @Html.Raw(Resources.C1Mvc.Parsing_Text6)
    <input id="dtIn" value="12/31/2016">
</label>
<button id="dtBtn" class="btn btn-default">
    @Html.Raw(Resources.C1Mvc.Parsing_Text7)
</button>
<br>
<div id="dtOutput">
</div>
 
<h2>
    @Html.Raw(Resources.C1Mvc.Parsing_Title2)
</h2>
<p>
    @Html.Raw(Resources.C1Mvc.Parsing_Text8)
</p>
 
<p>
    @Html.Raw(Resources.C1Mvc.Parsing_Text9)
</p>
<label>
    @Html.Raw(Resources.C1Mvc.Parsing_Text10)
    <input id="numFmt" value="n2">
</label>
<label>
    @Html.Raw(Resources.C1Mvc.Parsing_Text11)
    <input id="numIn" value="123.456">
</label>
<button id="numBtn" class="btn btn-default">
    @Html.Raw(Resources.C1Mvc.Parsing_Text12)
</button>
<br>
<div id="numOutput">
</div>
 
<div style="margin-bottom:2in">
</div>