08.09.2009, 18:05 | #1 |
Участник
|
mscrm4ever: Formatting CRM DateTime Field
Источник: http://mscrm4ever.blogspot.com/2009/...ime-field.html
============== As you might have noticed CRM DateTime field DataValue returns the following value: “Tue Sep 29 13:00:00 PDT 2009” Sometimes you need to change the value to another format e.g. dd/mm/yyyy or mm-dd-yyyy hh:MM. This is quite easy to do with C# since the format string is pretty extensive however the JavaScript Date object is pretty slim and so the only option is to write your own framework / prototype extension. The following script extends the JavaScript Date Object and adds a toFormattedString function which accepts common format strings such as dd – days, mm – months, yyyy – full year, hh – hours , MM – minutes , ss – seconds , ms – milliseconds , APM – AM/PM You can extend the prototype function further if you require additional formatting. Here is the code and usage example: Date.prototype.toFormattedString = function(format) { var d = this; var f = ""; f = f + format.replace( /dd|mm|yyyy|MM|hh|ss|ms|APM|\s|\/|\-|,|\./ig , function match() { switch(arguments[0]) { case "dd": var dd = d.getDate(); return (dd < 10)? "0" + dd : dd; case "mm": var mm = d.getMonth() + 1; return (mm < 10)? "0" + mm : mm; case "yyyy": return d.getFullYear(); case "hh": var hh = d.getHours(); return (hh < 10)? "0" + hh : hh; case "MM": var MM = d.getMinutes(); return (MM < 10)? "0" + MM : MM; case "ss": var ss = d.getSeconds(); return (ss < 10)? "0" + ss : ss; case "ms": return d.getMilliseconds(); case "APM": var apm = d.getHours(); return (apm < 12)? "AM" : "PM"; default: return arguments[0]; } } ); return f; } function OnCrmPageLoad() { var d = new Date(crmForm.all..DataValue); alert(d.toFormattedString("mm-dd-yyyy hh:MM:ss ms")); alert(d.toFormattedString("dd/mm/yyyy hh:MM APM")); } OnCrmPageLoad(); Источник: http://mscrm4ever.blogspot.com/2009/...ime-field.html
__________________
Расскажите о новых и интересных блогах по Microsoft Dynamics, напишите личное сообщение администратору. |
|
14.09.2010, 13:45 | #2 |
Участник
|
Полезная штуковина!
|
|
|
|