Конференция "Начинающим" » Есть ли функция DateToISO8601 в дельфи 2007?
 
  • Abcdef123 © (28.05.18 06:56) [0]
    Здравствуйте, Мастера!
    Мне нужно представить дату в формате ISO 8601 - UTC. Я в инете нашда, что в новой версии Дельфи есть фунция для этого DateToISO8601, а вот в D2007 может я просто не нашла?
    Как решить эту проблему в В2007?
    Заранее благодарна,
    Надежда
  • Плохиш © (28.05.18 12:24) [1]

    > Как решить эту проблему в В2007?

    В связи с тем, что моя гугля выдала мне на первой же странице полное описание требуемого решения с исходниками, вам необходимо купить новую версию delphi.
  • Abcdef123 © (29.05.18 11:13) [2]
    To [1] Спасибо за отклик, но,на данный момент все проекты в версии 2007, перевести на новую версию требуется много времени, а фукцию применить надо сейчас в одном из действующих взаимосвязанных проектов.
  • Плохиш © (29.05.18 15:39) [3]
  • han_malign © (30.05.18 09:25) [4]

    > Плохиш ©   (29.05.18 15:39) [3]

    - XSBuiltIns... - мелковат микроскоп, надо было что-нибудь через обращение к онлайн-сервисам Google поискать...

    > ISO 8601 - UTC


    var st: TSystemTime;
        ft, lft: TFileTime;
        basic_ISO8601: string;
        exetnded_ISO8601: string;
    begin
       DateTimeToSystemTime(dt, st);
       SystemTimeToFileTime(st, lft);
       LocalFileTimeToFileTime(lft, ft); // UTC!
       FileTimeToSystemTime(ft, st);
       
       basic_ISO8601:= FormatDateTime('yyyymmdd"T"hhnnss"Z"',SystemTimeToDateTime(st));
       extended_ISO8601:= FormatDateTime('yyyy-mm-dd"T"hh":"nn":"ss"Z"',SystemTimeToDateTime(st));
      // SysUtils: "   :       Displays the time separator character given by the TimeSeparator global variable."
      // so enclose ":"
      ...

    Можно было бы через честный Format("%04u%02u%02", [st.wYear, st.wMonth, st.wDay]), но он не умеет дополнять '0', как sprintf().
  • Плохиш © (30.05.18 10:16) [5]

    > han_malign ©   (30.05.18 09:25) [4]

    понимаю, долго ждал, пока сжалятся над просящей, чтобы блеснуть.
  • Abcdef123 © (30.05.18 13:13) [6]
    В приведенном по ссылке коду результат не совсем такой получается как надо (отличается от дельфийского DateToISO8601), но тем не менее - большое спасибо за ссылку!
  • Inovet © (30.05.18 16:24) [7]
    > [4] han_malign ©   (30.05.18 09:25)

    А сдвиг от мирового времени?
  • han_malign © (30.05.18 18:02) [8]

    > А сдвиг от мирового времени?

    - UTC aka Zulu = +0000 = Z
  • Inovet © (30.05.18 23:45) [9]
    > [8] han_malign ©   (30.05.18 18:02)
    > - UTC aka Zulu = +0000 = Z

    Я про формат с указанием местного времени и смещения.
  • han_malign © (31.05.18 13:17) [10]

    > Я про формат

    Заказывали UTC, а так выбирай на вкус, например - даты

    Basic format: YYYYMMDD Example: 19850412
    Extended format: YYYY-MM-DD Example: 1985-04-12

    Basic format: ±YYYYYMMDD Example: +0019850412
    Extended format: ±YYYYY-MM-DD Example: +001985-04-12

    Basic format: ±YYYYYDDD Example: +001985102
    Extended format: ±YYYYY-DDD Example: +001985-102

    Basic format: YYYYWwwD Example: 1985W155
    Extended format: YYYY-Www-D Example: 1985-W15-5

    - всё это ISO 8601

    ISO 8601:2004(E)

    The zone designator is empty if use is made of local time in accordance with 4.2.2.2 through 4.2.2.4, it is the
    UTC designator [Z] if use is made of UTC of day in accordance with 4.2.4
    and it is the difference-component if
    use is made of local time and the difference from UTC in accordance with 4.2.5.2.

    The character [T] shall be used as time designator to indicate the start of the representation of the time of day
    component in these expressions. The hyphen [-] and the colon [:] shall be used, in accordance with 4.4.4, as
    separators within the date and time of day expressions, respectively, when required.

    NOTE By mutual agreement of the partners in information interchange, the character [T] may be omitted in
    applications where there is no risk of confusing a date and time
    of day representation with others defined in this
    International Standard.

    The following are examples of complete representations of date and time of day representations:

    Basic format: YYYYMMDDThhmmss Example: 19850412T101530
    YYYYMMDDThhmmssZ 19850412T101530Z
    YYYYMMDDThhmmss±hhmm 19850412T101530+0400
    YYYYMMDDThhmmss±hh 19850412T101530+04

    Extended format: YYYY-MM-DDThh:mm:ss Example: 1985-04-12T10:15:30
    YYYY-MM-DDThh:mm:ssZ 1985-04-12T10:15:30Z
    YYYY-MM-DDThh:mm:ss±hh:mm 1985-04-12T10:15:30+04:00
    YYYY-MM-DDThh:mm:ss±hh 1985-04-12T10:15:30+04

    Where complete representations using calendar dates are shown, ordinal dates (4.1.3.2) or week dates
    (4.1.4.2) may be substituted
    .
 
Конференция "Начинающим" » Есть ли функция DateToISO8601 в дельфи 2007?
Есть новые Нет новых   [118686   +15][b:0][p:0]