日期时间转换为 Xa6maSA 格式

DateTime Convert to Xa6maSA format

在 Naumen 服务台(类似于 HPE Service Manager),我需要模拟POST请求,请求本身包含特殊格式的日期,我需要将日期转换成这种格式。 服务本身写在Java.

1609459200 01.01.2021 00:00 Xa6maSA
1609545600 01/02/2021 00:00 Xa_wACA
1609632000 01/03/2021 00:00 XbE5lyA
1199145600 01/01/2008 00:00 RcyAPiA
1514795559 01/01/2018 00:00 WCuX8SA
1014795559 02/27/2002 00:00 OxEPhCA

例如,我正在尝试将日期“01/02/2021 00:00”转换为“Xa_wACA”形式。 我试图从 base64 解码但无济于事。我尝试以相同的方式在 UNIX 和 base64 中进行编码。我不明白“Xa_wACA”是什么日期格式。也许我还需要注意“dateTime|fromTo|215b46e2-f09c-1c21-beb3-e8dece85f901|java.util.Date/3385151746|5348e408-7d47-39fb-0d27-6a46c169d631|28a1b768-8175 行-1992-e797-789c41c6164e”在 RequestPayload 中。 此请求正在通过日期期限。 请帮助我。

请求负载

7|0|187|https://*//|7489306D370535F304552E7CCFF88EF8|net.customware.gwt.dispatch.shared.standard.StandardDispatchService|execute|net.customware.gwt.dispatch.shared.Action|ru.naumen.metainfo.shared.dispatch2.GetDataForObjectListAction/2024037157|ru.naumen.objectlist.shared.ObjectListDataContextImpl/3114176613|ru.naumen.objectlist.shared.ObjectListClientState/1656993251|java.util.ArrayList/4159755760|java.lang.String/2004016611|serviceCall@registrationDate|abstractBO@system_icon|abstractBO@title|serviceCall@state|serviceCall@slmService|serviceCall@seviceComp|serviceCall@route|serviceCall@descriptionInRTF|serviceCall@ConfigItems|serviceCall@responsibleTeam|serviceCall@responsibleEmployee|serviceCall@deadLineTime|serviceCall@overdueState|serviceCall@dateDecision|serviceCall@procCodeClose|serviceCall@solution|serviceCall@solvedByTeam|serviceCall@solvedByEmployee|serviceCall@numRef|serviceCall@resumptionSum|serviceCall@priority|serviceCall@impact|serviceCall@urgency|serviceCall@wayAddressing|serviceCall@mark|serviceCall@place|serviceCall@userName|serviceCall@headOuUser|serviceCall@linkedSC|serviceCall$services@TimeToRectific|serviceCall@techDesc|serviceCall@ScLinks|serviceCall@stDoneChildSc|serviceCall$services@Reaction1Line|serviceCall$services@Reaction2Line|serviceCall$services@Reaction3Line|serviceCall$services@Reaction4Line|serviceCall$services@TimeWork1Line|serviceCall$services@TimeWork2Line|serviceCall$services@TimeWork3Line|serviceCall$services@TimeWork4Line|abstractBO@lastModifiedDate|serviceCall@analyticalFeat|serviceCall@clientState|serviceCall$changeRequest@TimeToRectific|serviceCall@idHolder|serviceCall@versionPpo|serviceCall@delayReason|serviceCall@inboxMailRule|serviceCall@autoRslvRsmSum|serviceCall@extId|serviceCall@activnost|serviceCall@circuit|serviceCall@subcategory|serviceCall@environment|serviceCall$problem@TimeToRectific|serviceCall@variantDecisio|serviceCall@extNumber|serviceCall@version|serviceCall$userCalls@TimeToRectific|serviceCall$userCalls@Reaction1Line|serviceCall$userCalls@Reaction2Line|serviceCall$userCalls@Reaction3Line|serviceCall$userCalls@Reaction4Line|serviceCall$userCalls@TimeWork1Line|serviceCall$userCalls@TimeWork2Line|serviceCall$userCalls@TimeWork3Line|serviceCall$userCalls@TimeWork4Line|serviceCall@numRtrnReclass|serviceCall@VIPCompany2|serviceCall@inn|serviceCall@solvedBy|serviceCall@parentServComp|abstractBO@author|serviceCall@userOrgType|serviceCall@returnDateTime|serviceCall@crIncStartDate|serviceCall@crIncEndDate|serviceCall@relatedPrb|serviceCall$knowledge@artModified|java.util.HashMap/1797211028|__window__|ru.naumen.metainfo.shared.TitledClassFqn/579494937|employee$employee#Сотрудник|employee625234|java.lang.Integer/3438268394|java.util.HashSet/3273092938|ru.naumen.metainfo.shared.ui.ObjectList/3529328647|ru.naumen.metainfo.shared.ui.ObjectActionsMenuHolder/1365266627|9582925f-e0c2-4ecb-b688-e54e0581e10b|ru.naumen.metainfo.shared.ui.LocalizedString/2069796573|ru|Запросы|ru.naumen.metainfo.shared.ClassFqn/3609641243|serviceCall|ru.naumen.metainfo.shared.ui.AdvlistSettingsDefault/1066691287|ru.naumen.metainfo.shared.ui.ListFilter/650544807|f8475341-1703-8838-0390-00007da9d7e6|ru.naumen.metainfo.shared.ui.ListSort/2408399067|f8475495-1703-923f-0390-00007da9d7e6|ru.naumen.metainfo.shared.ui.ToolPanel/4203276542|85174c18-72e1-4610-efb6-2a305f9fbb85|f83bdb97-1703-171c-0386-00007da9d7e6|ru.naumen.metainfo.shared.ui.PagingSettings/3865630973|ru.naumen.metainfo.shared.ui.PagerPosition/228906125|advlist|ru.naumen.metainfo.shared.ui.ToolBar/1303225976|ru.naumen.metainfo.shared.ui.AdvlistPrsSelectTool/1989409781|currentObject|ru.naumen.common.shared.utils.MapProperties/267701359|default|f544db61-174b-675b-008b-00005c7fef0d|ru.naumen.metainfo.shared.ui.ActionTool/1275350531|saveAdvlistPrs|Сохранить вид|en|Save view|save_icon|defaultIconOnly|f544db61-174b-675e-008b-00005c7fef0d|74c0188e-1fad-fba1-31bd-d0b51d21e866|showAdvlistSort|Сортировка...|Sort|sort_button|pushImageOnly|f83c557b-1703-ca35-0386-00007da9d7e6|showAdvlistFilter|Фильтрация...|Filtration|filter_button|f83c557b-1703-ca37-0386-00007da9d7e6|f83c557b-1703-ca36-0386-00007da9d7e6|exportAdvlist|Экспорт списка|Export list|exp_icon|f83c557b-1703-ca38-0386-00007da9d7e6|f83c557b-1703-ca3a-0386-00007da9d7e6|1eb64ce8-ec35-e236-7682-f708ffde9cca|ru.naumen.metainfo.shared.ui.Position/1188886171|645251a8-0cc5-086e-3451-08b9ae12032d|Zaprosy|ru.naumen.metainfo.shared.ui.ListFilterAndElement/2826904725|ru.naumen.metainfo.shared.ui.ListFilterOrElement/881046284|isAttributeOfRelatedObject|false|isLinkToParent|attrTypeCode|object|conditionCode|contains|attributeFqn|aeb8203b-f221-21e7-acf5-f7e085e2bdb6|ru.naumen.core.shared.dto.SimpleDtObject/3309615647|removed|java.lang.Boolean/476441737|metaClass|team$autoRouteTeams|UUID|team1449638|title|МРФ ЦОКР28 Группа сопровождения ППО|valueType|dtObject|5e7e6aee-6b7e-a761-8487-ef63d3f21078|21f1030f-d3d0-eb67-1c4f-efdcaf0d72c1|dateTime|fromTo|215b46e2-f09c-1c21-beb3-e8dece85f901|java.util.Date/3385151746|5348e408-7d47-39fb-0d27-6a46c169d631|28a1b768-8175-1992-e797-789c41c6164e|ru.naumen.metainfo.shared.ui.ListSortElement/3850937752|Дата/время регистрации|cf16a2ee-9bb9-2402-f9b7-f75a5e6e2278|2ccfc304-2440-6cdb-a974-99437f03a5e4|1|2|3|4|1|5|6|7|8|9|80|10|11|10|12|10|13|10|14|10|15|10|16|10|17|10|18|10|19|10|20|10|21|10|22|10|23|10|24|10|25|10|26|10|27|10|28|10|29|10|30|10|31|10|32|10|33|10|34|10|35|10|36|10|37|10|38|10|39|10|40|10|41|10|42|10|43|10|44|10|45|10|46|10|47|10|48|10|49|10|50|10|51|10|52|10|53|10|54|10|55|10|56|10|57|10|58|10|59|10|60|10|61|10|62|10|63|10|64|10|65|10|66|10|67|10|68|10|69|10|70|10|71|10|72|10|73|10|74|10|75|10|76|10|77|10|78|10|79|10|80|10|81|10|82|10|83|10|84|10|85|10|86|10|87|10|88|10|89|10|90|91|0|0|0|91|0|92|93|94|95|0|0|141|0|96|20|0|0|0|0|0|0|0|0|91|0|97|80|-5|-6|-7|-8|-9|-10|-11|-12|-13|-14|-15|-16|-17|-18|-19|-20|-21|-22|-23|-24|-25|-26|-27|-28|-29|-30|-31|-32|-33|-34|-35|-36|-37|-38|-39|-40|-41|-42|-43|-44|-45|-46|-47|-48|-49|-50|-51|-52|-53|-54|-55|-56|-57|-58|-59|-60|-61|-62|-63|-64|-65|-66|-67|-68|-69|-70|-71|-72|-73|-74|-75|-76|-77|-78|-79|-80|-81|-82|-83|-84|98|91|0|99|0|0|0|1|9|0|9|0|100|9|1|101|102|103|104|105|106|9|0|1|107|9|0|0|0|1|0|9|0|9|0|108|1|109|9|0|1|0|9|0|9|0|110|1|20|0|0|111|0|0|1|9|0|0|1|-91|9|0|9|0|112|1|107|9|0|0|0|1|0|9|0|9|0|113|1|114|115|1|116|1|111|0|0|1|9|3|117|0|0|9|0|9|2|118|119|0|0|120|0|1|121|1|-121|9|0|9|0|122|1|123|124|1|9|2|101|102|125|101|126|127|0|119|128|0|120|0|1|129|1|-121|9|0|9|0|130|1|1|-119|9|0|9|0|131|1|117|0|0|9|0|9|2|123|132|1|9|2|101|102|133|101|126|134|0|119|135|0|120|0|1|136|1|-137|9|0|9|0|137|1|123|138|1|9|2|101|102|139|101|126|140|0|119|141|0|120|0|1|136|1|-137|9|0|9|0|142|1|1|-119|9|0|9|0|143|1|117|0|0|9|0|9|1|123|144|1|9|2|101|102|145|101|126|146|0|119|147|0|120|0|1|129|1|-156|9|0|9|0|148|1|1|-119|9|0|9|0|149|1|0|1|-91|9|0|9|0|150|1|151|2|107|9|0|0|0|1|0|9|0|9|0|152|1|1|0|9|0|9|0|153|1|107|9|2|154|9|2|155|91|5|10|156|10|157|10|158|-184|10|159|10|160|10|161|10|162|10|163|-21|164|165|91|0|91|0|120|5|166|167|0|168|104|169|170|10|171|172|10|173|174|10|175|0|155|91|5|-183|-184|-185|-184|-186|-187|-188|-189|-190|-14|176|165|91|0|91|0|120|5|166|167|0|168|-196|170|-197|172|-198|174|-199|0|1|0|0|0|177|1|154|9|1|155|91|5|-183|-184|-185|-184|-186|10|178|-188|10|179|-190|-5|180|9|2|181|**OxEPhCA**|181|**XdaPd4g**|0|1|0|0|0|182|1|0|0|1|0|0|0|183|1|109|9|1|184|0|11|185|1|0|0|0|186|1|1|0|9|0|9|0|187|1|9|0|

这是自纪元以来的base 64编码时间

Base 64 编码正确(显然是 RFC 4648 §5:base64url 变体)。自 1970 年 1 月 1 日在 00:00 UTC 的 Unix 纪元以来,这样编码的数字计数为 4 毫秒单位。此外,您的日期和时间似乎位于 UTC 偏移量 +03:00 的时区内,例如 Europe/Moscow、Europe/Kirov 或 Europe/Volgograd.

    ZoneId zone = ZoneId.of("Europe/Moscow");
    
    Base64.Decoder decoder = Base64.getDecoder();
    String[] naumenStrings = { "Xa6maSA", "Xa_wACA", "XbE5lyA", "RcyAPiA", "WCuX8SA", "OxEPhCA" };
    for (String naumen : naumenStrings) {
        String base64 = naumen.replace('-', '+').replace('_', '/');
        byte[] ba = decoder.decode(base64);
        long milli4s = new BigInteger(ba).longValueExact();
        Instant inst = Instant.EPOCH.plus(milli4s * 4, ChronoUnit.MILLIS);
        ZonedDateTime dateTime = inst.atZone(zone);
        System.out.println(dateTime);
    }

此片段输出与您问题中相同的日期和时间:

2021-01-01T00:00+03:00[Europe/Moscow]
2021-01-02T00:00+03:00[Europe/Moscow]
2021-01-03T00:00+03:00[Europe/Moscow]
2008-01-01T00:00+03:00[Europe/Moscow]
2018-01-01T00:00+03:00[Europe/Moscow]
2002-02-27T00:00+03:00[Europe/Moscow]

Base64.Decoder 的文档声称它支持 RFC 4648,但我无法让它工作。相反,我将字符 -_ 替换为更常见的 base 64 编码 +/.

正在将 转换为 Naumen Service Desk 格式

对于相反的转换:

    Base64.Encoder encoder = Base64.getEncoder().withoutPadding();
    ZoneId zone = ZoneId.of("Europe/Moscow");
    
    ZonedDateTime[] dateTimes = {
            ZonedDateTime.of(2021, 1, 1, 0, 0, 0, 0, zone),
            ZonedDateTime.of(2021, 3, 6, 17, 0, 0, 0, zone)
    };
    for (ZonedDateTime zdt : dateTimes) {
        long epochMillis = zdt.toInstant().toEpochMilli();
        byte[] ba = BigInteger.valueOf(epochMillis / 4).toByteArray();
        String base64 = encoder.encodeToString(ba);
        String naumen = base64.replace('+', '-').replace('/', '_');
        System.out.println("" + zdt + " -> " + naumen);
    }

输出:

2021-01-01T00:00+03:00[Europe/Moscow] -> Xa6maSA
2021-03-06T17:00+03:00[Europe/Moscow] -> XgH1nsA

在输出中,您从问题和问题标题中识别出字符串 Xa6maSAwithoutPadding() 调用抑制了 = 填充字符,否则将附加到编码字符串。

链接