在对DateTime做处理的时候,会用到一个系统的类 DateTimeUtil,他提供了很多对dateTime处理以及转换的方法,下面有个例子,实现对日月年时分秒的任意排列组合。
getstrDMYHMS() : D – 日 M – 月 Y – 年 H – 时 M – 分 S – 秒
//源代码
str getstrDMYHMS()
{
Date dateNow;
utcDateTime dateTime;
str hhmmss,tmp='';
;
//获取当前系统时间
dateTime = DateTimeUtil::getSystemDateTime();
//根据公司选择的时区将系统的时间转化为公司所选时区时间
dateTime = DateTimeUtil::applyTimeZoneOffset(dateTime,DateTimeUtil::getCompanyTimeZone());
dateNow = DateTimeUtil::date(dateTime);
tmp = int2str(DateTimeUtil::hour(dateTime));
if (strlen(tmp) ==1)
{
tmp = "0" + tmp;
}
hhmmss = tmp;
tmp = int2str(DateTimeUtil::minute(dateTime));
if (strlen(tmp) == 1)
{
tmp = "0" + tmp;
}
hhmmss += tmp;
tmp = int2str(DateTimeUtil::second(dateTime));
if (strlen(tmp) == 1)
{
tmp = "0" + tmp;
}
hhmmss += tmp;
return date2str(dateNow,123,2,0,2,0,4) + hhmmss;
}
本文介绍了一个系统类DateTimeUtil的功能及使用方法,该类提供了一系列处理和转换日期时间的实用工具。通过具体实例展示了如何获取并格式化当前系统时间,包括应用公司时区偏移和按需组合日期时间元素。
8万+

被折叠的 条评论
为什么被折叠?



