0

如何获取现有的LocalDateTime(我从回调中获取)并能够将其转换为UTC格式?

public static LocalDateTime convertXMLGregorianCalendarToDateUTC(XMLGregorianCalendar xmlGregorianCalendar) {
    // Next shows GMT or UTC
    return LocalDateTime.of(xmlGregorianCalendar.getYear(), xmlGregorianCalendar.getMonth(),
            xmlGregorianCalendar.getDay(), xmlGregorianCalendar.getHour(), xmlGregorianCalendar.getMinute(),
            xmlGregorianCalendar.getSecond());
}

我正在使用 mapstruct 进行映射:

@Mapping(target = "targetDateTime", source = "sourceDateTime", qualifiedByName = "timeToUTC")
})
void updateFolderEntity(FolderEntity folderEntity);

我有一个简单的助手来创建一个函数,该函数接受回调给我的内容并以 UTC 形式返回:

@Named("timeToUTC")
public LocalDateTime timeToUTC(LocalDateTime localDateTime) {
    // stuck here !
 return DateUtils.convertXMLGregorianCalendarToDateUTC(callBackUserService.getUser().get(0).getDateAction());
}

问题是这callBackUserService.getUser().get(0).getDateAction()实际上是我需要转换的日期,但 mapStruct 不允许我进行映射,因为CallBackUserService callBackUserService它不能作为参数,public LocalDateTime timeToUTC(LocalDateTime localDateTime) 因为我的源是sourceDateTime并且它只是一种类型,它是LocalDateTime

4

0 回答 0