将UTC字符串转换为Crystal Reports中的日期的最佳方法是什么?

时间:2008-11-07 03:16:50

标签: string crystal-reports

给出如下的UTC时间字符串:

2005-11-01T00:00:00-04:00

使用Crystal Reports公式将其转换为DateTime的最佳方法是什么?

我的最佳解决方案发布在下面。

我希望那里的某个人可以用一个班轮吹我...

4 个答案:

答案 0 :(得分:3)

我可以建议简化jons911的答案:

CDateTime(CDate(Left({@UTCString}, 10)), CTime(Mid({@UTCString}, 12, 8)));  

这具有以下优点:该公式适用于UTC 0前面的时区(例如+01:00)。它当然依赖于UTC字符串是格式正确的ISO 8601字符串。

答案 1 :(得分:2)

你走了:

CDateTime(CDate(Split({?UTCDateString},“T”)[1]),CTime(Split(Split({?UTCDateString},“T”)[2],“ - ”)[1]) )

答案 2 :(得分:1)

这是我最好的解决方案,有评论:

//assume a date stored as a string in this format:
//2005-11-01T00:00:00-04:00
//return a DateTime value
StringVar fieldValue;
StringVar datePortion;
StringVar timePortion;
NumberVar yearPortion;
NumberVar monthPortion;
NumberVar dayPortion;
NumberVar hourPortion;
NumberVar minutePortion;
NumberVar secondPortion;

//store the field locally so i can easily copy-paste into another formula
//(where the field name will be different)
//Crystal formulas do not use a powerful language.
fieldValue := {PACT.ReferralDate};

//break up the date & time parts.
//ignore the -04:00 offset part of the time.
datePortion := Split (fieldValue,"T")[1];
timePortion := Split(Split (fieldValue,"T")[2],"-")[1];

yearPortion := ToNumber(Split(datePortion,"-")[1]);
monthPortion := ToNumber(Split(datePortion,"-")[2]);
dayPortion := ToNumber(Split(datePortion,"-")[3]);

hourPortion := ToNumber(Split(timePortion,":")[1]);
minutePortion := ToNumber(Split(timePortion,":")[2]);
secondPortion := ToNumber(Split(timePortion,":")[3]);

//finally, return the result as a date-time
DateTime(yearPortion,monthPortion,dayPortion,hourPortion,minutePortion,secondPortion);

答案 3 :(得分:0)

StringVar fieldValue;
StringVar datePortion;
StringVar timePortion;
NumberVar yearPortion;
NumberVar monthPortion;
NumberVar dayPortion;
NumberVar hourPortion;
NumberVar minutePortion;
NumberVar secondPortion;
datetimevar dtlimite;

fieldValue := {dtsecretaria.Data_limite};

datePortion := Split (fieldValue,"T")[1];
timePortion := Split(Split (fieldValue,"T")[2],"-")[1];

yearPortion := ToNumber(Split(datePortion,"-")[1]);
monthPortion := ToNumber(Split(datePortion,"-")[2]);
dayPortion := ToNumber(Split(datePortion,"-")[3]);

hourPortion := ToNumber(Split(timePortion,":")[1]);
minutePortion := ToNumber(Split(timePortion,":")[2]);
secondPortion := ToNumber(Split(timePortion,":")[3]);

dtlimite := DateTime(yearPortion,monthPortion,dayPortion,hourPortion,minutePortion,secondPortion);


if dtlimite > CurrentDateTime then

Color(255,0,0)

else

Color(255,255,0)



error of nError in formula  <Back_Color>. \n'\r'\nA string is required here."