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

 
 
Опции темы Поиск в этой теме Опции просмотра
Старый 30.01.2015, 01:15   #1  
Blog bot is offline
Blog bot
Участник
 
25,475 / 846 (79) +++++++
Регистрация: 28.10.2006
goshoom: Custom date and time format
Источник: http://dev.goshoom.net/en/2015/01/cu...tetime-format/
==============

I was extending a customization of Dynamics AX when I ran into the following piece of code. It formats the current date and time to something like 20150525_0042.

str dateValue, dateFormat; dateValue = date2str( systemDateGet(), 321, DateDay::Digits2, DateSeparator::None, DateMonth::Digits2, DateSeparator::None, DateYear::Digits4, DateFlags::FormatAll); dateFormat = strFmt( "%1%2%3", dateValue, '_', subStr( strRem(time2Str(timeNow(), TimeSeparator::Space, TimeFormat::Auto), ' '), 0, 4));






If I haven’t formatted the code to make it more readable, you would struggle to follow what it does. Even the original developer had the same problem – I already fixed two bugs (!) in this code snippet.

I rather dropped the code completely and replaced it with this:

str formatted = System.String::Format( '{0:yyyyMMdd_HHmm}', DateTimeUtil::newDateTime(systemDateGet(), timeNow()));






Better, isn’t it? It’s not only shorter, more importantly it’s much easier to understand and maintain. It would be even simpler if I used DateTimeUtil::utcNow() instead of keeping the original logic with systemDateGet() and timeNow().

This is just a simple example of how .NET Interop from X++ can make your life easier – the amount of .NET code available for you is huge. In this particular case, I called String.Format() method with a custom date and time format. You can also use custom formats when parsing strings to dates (DateTime.ParseExact()), which is probably even more useful.



Источник: http://dev.goshoom.net/en/2015/01/cu...tetime-format/
__________________
Расскажите о новых и интересных блогах по Microsoft Dynamics, напишите личное сообщение администратору.
 

Похожие темы
Тема Автор Раздел Ответов Посл. сообщение
daxmusings: Valid Time State/Date Effective Framework - Part2 Blog bot DAX Blogs 6 07.10.2011 11:22
Aku: Dynamics AX AIF Webservices – Date, Time und Datetime Datentypen Blog bot DAX Blogs 0 22.04.2011 17:11
axaptapedia: Current Time Blog bot DAX Blogs 1 29.11.2010 22:11
Dynamics AX Sustained Engineering: Date\time data reflected in User's preferred time zone after conversion from UTC Blog bot DAX Blogs 0 10.08.2010 02:07
CRM DE LA CREME! Some more useful javascripts for MS CRM Blog bot Dynamics CRM: Blogs 0 04.05.2010 11:05

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

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

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