AXForum  
Вернуться   AXForum > Microsoft Dynamics CRM > Dynamics CRM: Blogs
All
Забыли пароль?
Зарегистрироваться Правила Справка Пользователи Сообщения за день Поиск

 
 
Опции темы Поиск в этой теме Опции просмотра
Старый 08.09.2009, 18:05   #1  
Blog bot is offline
Blog bot
Участник
 
25,477 / 846 (79) +++++++
Регистрация: 28.10.2006
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  
Kipetcoff is offline
Kipetcoff
Участник
 
136 / 16 (1) ++
Регистрация: 20.05.2009
Адрес: Санкт-Петербург
Полезная штуковина!
 

Похожие темы
Тема Автор Раздел Ответов Посл. сообщение
CRM DE LA CREME! Configuring Microsoft Dynamics CRM 4.0 for Internet-facing deployment Blog bot Dynamics CRM: Blogs 0 18.08.2009 11:05
Microsoft Dynamics CRM Team Blog: Building Rich-Client Dashboards for Microsoft Dynamics CRM with Windows Presentation Foundation Blog bot Dynamics CRM: Blogs 1 31.03.2009 13:24
mscrm4ever: CRM 4.0 Concatenating Fields Plug-In Blog bot Dynamics CRM: Blogs 0 14.02.2009 14:05
Microsoft Dynamics CRM Team Blog: List Web Part for Microsoft Dynamics CRM 4.0 Deployment Scenarios Blog bot Dynamics CRM: Blogs 0 30.01.2009 22:05
Microsoft Dynamics CRM Team Blog: List Web Part for Microsoft Dynamics CRM 4.0: Understanding Connections Blog bot Dynamics CRM: Blogs 0 20.01.2009 02:07

Ваши права в разделе
Вы не можете создавать новые темы
Вы не можете отвечать в темах
Вы не можете прикреплять вложения
Вы не можете редактировать свои сообщения

BB коды Вкл.
Смайлы Вкл.
[IMG] код Вкл.
HTML код Выкл.
Быстрый переход

Рейтинг@Mail.ru
Часовой пояс GMT +3, время: 00:44.
Powered by vBulletin® v3.8.5. Перевод: zCarot
Контактная информация, Реклама.