在ABSL中将毫秒转换为日期

2020-08-15 20:06发布

点击此处---> 群内免费提供SAP练习系统(在群公告中)加入QQ群:457200227(SAP S4 HANA技术交流) 群内免费提供SAP练习系统(在群公告中)嗨, ABSL中是否有标准功...

         点击此处--->   EasySAP.com群内免费提供SAP练习系统(在群公告中)

加入QQ群:457200227(SAP S4 HANA技术交流) 群内免费提供SAP练习系统(在群公告中)


嗨,

ABSL中是否有标准功能可以将JSON毫秒日期(EPOCH日期)转换为日期时间?

谢谢

凯文

4条回答
路亽曱_Ryan
2020-08-15 20:53 .采纳回答

感谢Sneha,我认为这可能是ABAP而不是ABSL,但我们也许可以使用其中的一些代码来简化我们的代码...我们已经弄清楚了,不确定它是否以最佳方式运行,但是否可行。 我们创建了2个重用函数来转换毫秒之间的时间(Epoch Date)。

这是毫秒字符串的转换

导入BASIS.Global;

 var结果:GLOBAL_DateTime;
 var trimContent = Content.Substring(0,10);
 var trimContentHalfSec = Content.Substring(10);
 var trimContentHalfSecNumber = Library :: Numeric.ParseFromString(trimContentHalfSec);
 var aSec = 0;

 var ePValue = Library :: Numeric.ParseFromString(trimContent);

 var epochstart =" 19700101000000";
//var epochdate = Library :: DateTime.ParseFromString(epochstart);
 var epochdate = GlobalDateTime.ParseFromString(epochstart);
//var epochstartJustDate = Library :: DateTime.ConvertToGlobalDateTime(epochdate);
 var epochstartJustDate = epochdate.ConvertToDate();

 if(trimContentHalfSecNumber> 499){aSec = 1;}
 var min = ePValue/60;
 var sec =(ePValue%60)+ aSec; //第二个值
 var secString = sec.ToString();

 var minTrimmedDecimal = min.ToString()。TrimRight(" 1234567890");
 var minTrimmDot = minTrimmedDecimal.TrimRight("。");

 var hrs = Library :: Numeric.ParseFromString(minTrimmDot)/60;
 var minRemainder = Library :: Numeric.ParseFromString(minTrimmDot)%60; //分钟值
 var minRemainderString = minRemainder.ToString();

 var hrsTrimmedDecimal = hrs.ToString()。TrimRight(" 1234567890");
 var hrsTrimmDot = hrsTrimmedDecimal.TrimRight("。");

 var dys = Library :: Numeric.ParseFromString(hrsTrimmDot)/24;
 var hrsRemainder = Library :: Numeric.ParseFromString(hrsTrimmDot)%24; //小时值
 var hrsRemainderString = hrsRemainder.ToString();

 var dysTrimmedDecimal = dys.ToString()。TrimRight(" 1234567890");
 var dysTrimmDot = dysTrimmedDecimal.TrimRight("。");

 dys = Library :: Numeric.ParseFromString(dysTrimmDot);

 var duration =" P" + dys.ToString()+" D";
//var addDuration = epochstartJustDate.AddDuration(Library :: Duration.ParseFromString(duration));
 var addDuration = epochstartJustDate.AddDuration(Library :: Duration.ParseFromString(duration));
 var dateAsString = addDuration.ToString();

 if(secString.Length()== 1){secString =" 0" + secString;}
 if(minRemainderString.Length()== 1){minRemainderString =" 0" + minRemainderString;}
 if(hrsRemainderString.Length()== 1){hrsRemainderString =" 0" + hrsRemainderString;}


 var ePochCalculatedString = dateAsString +" T" + hrsRemainderString +":" + minRemainderString +":" + secString +" Z";
 var epochCalcDate = Library :: DateTime.ParseFromString(ePochCalculatedString);
 var ePochCalculatedDate = Library :: DateTime.ConvertToGlobalDateTime(epochCalcDate);

 结果= ePochCalculatedDate;

 返回结果; 

一周热门 更多>