javascript - Format Date in JS from .NET Service AJAX call -


i have problem. date .net service ajax call. format of date got (i in italy)

mon dec 31 2012 08:25:21 gmt+0100 (ora solare europa occidentale)    

how can format date in format dd/mm/yyyy ? cannot work on .net service side, js side. in advance.

you can parse bits date object, create formatted string in whatever format want. following takes account of timezone, might different client:

var s = 'mon dec 31 2012 08:25:21 gmt+0100';  function getdate(s) {      // split string bits     var s = s.split(/[ :]/);      // conversion month month number (zero indexed)     var months = {jan:0,feb:1,mar:2,apr:3,may:4,jun:5,                   jul:6,aug:7,sep:8,oct:9,nov:10,dec:11};      // calculate offset in minutes     var offsetmins = s[7].substring(4,6) * 60;     offsetmins += s[7].substring(6,8) * 1;     offsetmins *= s[7].substring(3,4) == '+'? 1 : -1;      // build utc date value, allowing offset in minutes,     // , pass date constructor     var date = new date(date.utc(s[3], months[s[1].tolowercase()],                s[2], s[4], (s[5] - offsetmins), s[6]));      // return date object     return date; }  function padn(n) {   return (n<10? '0' : '') + n; }  var d = getdate(s);  alert(padn(d.getdate()) + '/' + padn(d.getmonth() + 1) + '/' + d.getfullyear());  

Comments

Popular posts from this blog

c++ - llvm function pass ReplaceInstWithInst malloc -

java.lang.NoClassDefFoundError When Creating New Android Project -

Decoding a Python 2 `tempfile` with python-future -