Todos os produtos
Search
Central de documentação

Simple Log Service:Funções de data e hora

Última atualização: Jun 23, 2026

As funções de data e hora permitem converter, extrair e manipular valores temporais nas regras de transformação do SLS DSL.

Na lógica de transformação do SLS DSL, todos os valores de log são armazenados como strings. Converta os tipos de dados conforme necessário para o seu cenário.

O tempo nos logs é representado por três tipos de dados principais. Utilize as funções de data e hora descritas aqui para converter entre esses formatos.

  • String

    Por exemplo, 2022/07/03 02-41-26.

  • UNIX timestamp

    Por exemplo, 1559500886.

  • Objeto datetime

    Por exemplo, 2022-07-01 10:10:10+08:00 or 2022-07-01 10:10:10.

null

Um timestamp UNIX também é uma string.

Among the date and time functions described here, only dt_parse, dt_str, and dt_parsetimestamp accept all three data types as parameters. For all other functions, parameter types must be consistent.

Funções

Category

Function

Description

Categoria

dt_parse

Função

dt_str

Descrição

dt_parsetimestamp

Conversão comum de data e hora

dt_prop

dt_parse

Converte um valor ou o valor de uma expressão de tempo em um objeto datetime.

dt_now

dt_str

dt_today

Converte um valor ou o valor de uma expressão de tempo em uma string.

dt_utcnow

dt_fromtimestamp

dt_parsetimestamp

dt_utcfromtimestamp

Converte um valor ou o valor de uma expressão de tempo em um timestamp UNIX.

dt_strptime

dt_prop

dt_currentstamp

Obtém propriedades específicas de um valor ou do valor de uma expressão de tempo, como dia e ano.

dt_totimestamp

Obter datetime

dt_strftime

dt_now

dt_strftimestamp

Obtém o objeto datetime atual.

dt_today

dt_truncate

Obtém a data atual sem o horário.

dt_add

dt_MO

A value passed to the weekday parameter of the dt_add function to specify an offset to a Monday.

dt_TU

A value passed to the weekday parameter of the dt_add function to specify an offset to a Tuesday.

dt_WE

A value passed to the weekday parameter of the dt_add function to specify an offset to a Wednesday.

dt_TH

A value passed to the weekday parameter of the dt_add function to specify an offset to a Thursday.

dt_FR

A value passed to the weekday parameter of the dt_add function to specify an offset to a Friday.

dt_SA

A value passed to the weekday parameter of the dt_add function to specify an offset to a Saturday.

dt_SU

A value passed to the weekday parameter of the dt_add function to specify an offset to a Sunday.

dt_utcnow

dt_astimezone

Obtém o objeto datetime atual no fuso horário atual.

dt_diff

dt_fromtimestamp

dt_parse

Converte um valor ou o valor de uma expressão de tempo em um objeto datetime.

  • Sintaxe

    dt_parse(value, tz=None)
  • Parâmetros

    Parameter Name

    Parameter type

    Required

    Description

    Nome do parâmetro

    Tipo de parâmetro

    Obrigatório

    Descrição

    value

    String, timestamp UNIX ou objeto datetime

    Sim

    The time zone. The default value is None. For more information, see Time zones.

  • Resposta

    Retorna o objeto datetime convertido.

  • Exemplos

    • Exemplo 1: Converte o valor do campo time em um objeto datetime.

      • Log bruto

        time: 1559500886
      • Transformation rule

        e_set("test_time", dt_parse(v("time")))
      • Result

        time: 1559500886
        test_time: 2019-06-02 18:41:26 
    • Example 2: Converts the value of the time field to a datetime object in the Asia/Shanghai time zone.

      • Raw log

        time: 2019-06-01 10:10:10
        tz: Asia/Shanghai
      • Transformation rule

        e_set("test_time", dt_parse(v("time"),tz=v("tz")))
      • Result

        time: 2019-06-01 10:10:10
        tz: Asia/Shanghai
        test_time: 2019-06-01 10:10:10+08:00

dt_str

Converte um valor ou o valor de uma expressão de tempo em uma string.

  • Sintaxe

    dt_str(value, fmt="format_string", tz=None)
  • Parâmetros

    Parameter Name

    Parameter type

    Required

    Description

    Nome do parâmetro

    Tipo de parâmetro

    Obrigatório

    Descrição

    value

    String, timestamp UNIX ou objeto datetime

    Sim

    The format string. For more information, see Date and time format directives. If you leave this empty, the original format is used. The default value is empty.

    O valor ou a expressão de tempo.

    fmt

    String

    The time zone. The default value is None. For more information, see Time zones.

  • Resposta

    Retorna a string de tempo convertida.

  • Exemplos

    • Exemplo 1: Converte o valor do campo time para o formato especificado no fuso horário Asia/Tokyo.

      • Log bruto

        time: 2019-06-03 02:41:26
        fmt: %Y/%m/%d %H-%M-%S
        tz: Asia/Tokyo
      • Transformation rule

        e_set("dt_str", dt_str(v("time"),fmt=v("fmt"),tz=v("tz")))
      • Result

        time: 2019-06-03 02:41:26
        fmt: %Y/%m/%d %H-%M-%S
        tz: Asia/Tokyo
        dt_str: 2019/06/03 02-41-26
    • Example 2: Converts the value of the time field, which is a UNIX timestamp, to the specified format.

      • Raw log

        time: 1559500886
        fmt: %Y/%m/%d %H-%M-%S
      • Transformation rule

        e_set("dt_str", dt_str(v("time"),fmt=v("fmt")))
      • Result

        time: 1559500886
        fmt: %Y/%m/%d %H-%M-%S
        dt_str: 2019/06/02 18-41-26
    • Example 3: Converts the value of the time field to the default format.

      • Raw log

        time: 2019-06-03 02:41:26
      • Transformation rule

        e_set("dt_str", dt_str(v("time")))
      • Result

        time: 2019-06-03 02:41:26
        dt_str: 2019-06-03 02:41:26

dt_parsetimestamp

Converte um valor ou o valor de uma expressão de tempo em um timestamp UNIX.

  • Sintaxe

    dt_parsetimestamp(value, tz=None)
  • Parâmetros

    Parameter

    Parameter type

    Required

    Description

    Parâmetro

    Tipo de parâmetro

    Obrigatório

    Descrição

    value

    String, timestamp UNIX ou objeto datetime

    Sim

    The time zone. The default value is None. For more information, see Time zones.

  • Resposta

    Retorna o timestamp UNIX convertido.

  • Exemplos

    • Exemplo 1: Converte o valor do campo time em um timestamp no fuso horário Asia/Tokyo.

      • Log bruto

        time: 2019-06-03 2:41:26
        tz: Asia/Tokyo
      • Transformation rule

        e_set("dt_parsetimestamp", dt_parsetimestamp(v("time"),v("tz")))
      • Result

        time: 2019-06-03 2:41:26
        tz: Asia/Tokyo
        dt_parsetimestamp: 1559497286
    • Example 2: Converts the value of the time field to a UNIX timestamp.

      • Raw log

        time: 2019-06-03 2:41:26
      • Transformation rule

        e_set("dt_parsetimestamp",dt_parsetimestamp(v("time")))
      • Result

        time: 2019-06-03 2:41:26
        dt_parsetimestamp: 1559529686
    • Example 3: Converts the value of the time field to a UNIX timestamp.

      • Raw log

        time: 2019-06-03 02:41:26+8:00
      • Transformation rule

        e_set("dt_parsetimestamp",dt_parsetimestamp(v("time")))
      • Result

        time: 2019-06-03 02:41:26+8:00
        dt_parsetimestamp: 1559500886

dt_prop

Extrai uma propriedade específica de um valor ou do valor de uma expressão de tempo, como o dia ou o ano.

  • Sintaxe

    dt_prop(value, props)
  • Parâmetros

    Parameter Name

    Parameter type

    Required

    Description

    Nome do parâmetro

    Tipo de parâmetro

    Obrigatório

    Descrição

    value

    String, timestamp UNIX ou objeto datetime

    Sim

    The time property to get. For example, if you set this parameter to year, only the year is returned. Valid values include day, year, month, hour, second, minute, microsecond, weekday, weekdayname, weekdayshortname, monthname, monthshortname, dayofyear, dayofweek, weekofyear, weekofyear_m, tzname, and weekofmonth.

  • Resposta

    Retorna a propriedade extraída.

  • Exemplos

    • Exemplo 1: Extrai a propriedade day do valor do campo time.

      • Log bruto

        time: 2018-10-2 09:11:40
      • Transformation rule

        e_set("dt_parsetimestamp",dt_prop(dt_parse(v("time")),"day"))
      • Result

        time: 2018-10-2 09:11:40
        dt_parsetimestamp: 2
    • Example 2: Extracts the year property from the value of the time field.

      • Raw log

        time: 2018-10-2 09:11:40
      • Transformation rule

        e_set("dt_parsetimestamp",dt_prop(dt_parse(v("time")),"year"))
      • Result

        time: 2018-10-2 09:11:40
        dt_parsetimestamp: 2018
    • Example 3: Extracts the weekdayname property from the value of the time field.

      • Raw log

        time: 2018-10-2 09:11:40
        weekdayname: weekdayname
      • Transformation rule

        e_set("dt_prop",dt_prop(dt_parse(v("time")),"weekdayname"))
      • Result

        time: 2018-10-2 09:11:40
        dt_prop: Tuesday
    • Example 4: Extracts the weekofyear property from the value of the time field.

      • Raw log

        time: 2018-10-2 09:11:40
      • Transformation rule

        e_set("dt_prop",dt_prop(dt_parse(v("time")),"weekofyear"))
      • Result

        time: 2018-10-2 09:11:40
        dt_prop: 39

dt_now

Retorna o objeto datetime atual.

  • Sintaxe

    dt_now(tz=None)
  • Parâmetros

    Parameter name

    Parameter Type

    Required

    Description

    Nome do parâmetro

    Tipo de parâmetro

    Obrigatório

    The time zone. The default value is None. For more information, see Time zones.

  • Resposta

    Retorna o objeto datetime atual.

  • Exemplos

    Retorna a hora atual no fuso horário Asia/Shanghai.

    • Log bruto

      tz: Asia/Shanghai
    • Transformation rule

      e_set("dt_now",dt_now(tz=v("tz")))
    • Result

      tz: Asia/Shanghai
      dt_now: 2022-06-30 11:21:25.111836+08:00

dt_today

Obtém a data atual sem o componente de hora.

  • Sintaxe

    dt_today(tz=None)
  • Parâmetros

    Parameter Name

    Parameter type

    Required

    Description

    Nome do parâmetro

    Tipo de parâmetro

    Obrigatório

    The time zone. The default value is None. For more information, see Time zones.

  • Resposta

    Retorna a data atual no formato AAAA-MM-DD 00:00:00.

  • Exemplos

    Retorna a data atual sem o componente de hora.

    • Log bruto

      None
    • Transformation rule

      e_set("dt_today", dt_today())
    • Result

      dt_today: 2022-06-30 00:00:00

dt_utcnow

Obtém o objeto datetime atual no fuso horário UTC.

  • Sintaxe

    dt_utcnow()
  • Parâmetros

    Nenhum.

  • Resposta

    Retorna o objeto datetime atual.

  • Exemplos

    Retorna a hora atual no fuso horário UTC.

    • Log bruto

      None
    • Transformation rule

      e_set("dt_utcnow",dt_utcnow())
    • Result

      dt_utcnow:2022-06-30 03:33:56.614005

dt_fromtimestamp

Converte um timestamp UNIX em um objeto datetime.

  • Sintaxe

    dt_fromtimestamp(value, tz=None)
  • Parâmetros

    Parameter Name

    Parameter type

    Required

    Description

    Nome do parâmetro

    Tipo de parâmetro

    Obrigatório

    Descrição

    value

    String

    Sim

    The time zone. The default value is None. For more information, see Time zones.

  • Resposta

    Retorna o objeto datetime convertido.

  • Exemplos

    • Exemplo 1: Converte o valor do campo time em um objeto datetime.

      • Log bruto

        time: 1559500886
      • Transformation rule

        e_set("dt_fromtimestamp",dt_fromtimestamp(v("time")))
      • Result

        time: 1559500886
        dt_fromtimestamp: 2019-06-02 18:41:26
    • Example 2: Converts the value of the time field to a datetime object in the Asia/Shanghai time zone.

      • Raw log

        time: 1559500886
        tz: Asia/Shanghai
      • Transformation rule

        e_set("dt_fromtimestamp",dt_fromtimestamp(v("time"),tz=v("tz")))
      • Result

        time: 1559500886
        tz: Asia/Shanghai
        dt_fromtimestamp: 2019-06-03 02:41:26+08:00

dt_utcfromtimestamp

Converte um timestamp UNIX em um objeto datetime no fuso horário atual.

  • Sintaxe

    dt_utcfromtimestamp(value)
  • Parâmetros

    Parameter

    Parameter type

    Required

    Description

    Parâmetro

    Tipo de parâmetro

    Obrigatório

    Descrição

  • Resposta

    Retorna o objeto datetime convertido.

  • Exemplos

    • Log bruto

      time: 1559500886
    • Transformation rule

      e_set("dt_utcfromtimestamp",dt_utcfromtimestamp(v("time")))
    • Result

      time: 1559500886
      dt_utcfromtimestamp: 2019-06-02 18:41:26

dt_strptime

Analisa uma string de tempo e a converte em um objeto datetime.

  • Sintaxe

    dt_strptime(value, "format_string")
  • Parâmetros

    Parameter Name

    Parameter type

    Required

    Description

    Nome do parâmetro

    Tipo de parâmetro

    Obrigatório

    Descrição

    value

    String

    Sim

    The format string. For more information, see Date and time format directives.

  • Resposta

    Retorna o objeto datetime analisado.

  • Exemplos

    • Log bruto

      time: 2019/06/03 02-41-26
      fmt: %Y/%m/%d %H-%M-%S
    • Transformation rule

      e_set("dt_strptime",dt_strptime(v("time"),v("fmt")))
    • Result

      time: 2019/06/03 02-41-26
      fmt: %Y/%m/%d %H-%M-%S
      dt_strptime: 2019-06-03 02:41:26

dt_currentstamp

Retorna o timestamp UNIX atual.

  • Sintaxe

    dt_currentstamp(value, normalize='floor')
  • Parâmetros

    Parameter Name

    Parameter Type

    Required

    Description

    Nome do parâmetro

    Tipo de parâmetro

    Obrigatório

    Descrição

    value

    String

    Sim

    O valor ou a expressão de tempo.

    • floor (default): Rounds the number down.

    • int: Returns the integer part.

    • round: Rounds the number.

    • ceil: Rounds the number up.

  • Resposta

    Retorna o timestamp UNIX atual.

  • Exemplos

    • Log bruto

      None
    • Transformation rule

      e_set("dt_currentstamp",dt_currentstamp())
    • Result

      dt_currentstamp: 1656560437

dt_totimestamp

Converte um objeto datetime em um timestamp UNIX.

  • Sintaxe

    dt_totimestamp(timeexpression)
  • Parâmetros

    Parameter Name

    Parameter type

    Required

    Description

    Nome do parâmetro

    Tipo de parâmetro

    Obrigatório

    Descrição

  • Resposta

    Retorna o timestamp UNIX convertido.

  • Exemplos

    • Log bruto

      time: 2019-06-03 2:41:26
    • Transformation rule

      e_set("dt_totimestamp",dt_totimestamp(dt_parse(v("time"))))
    • Result

      time: 2019-06-03 2:41:26
      dt_totimestamp: 1559529686

dt_strftime

Converte um objeto datetime em uma string no formato especificado.

  • Sintaxe

    dt_strftime(timeexpression, "format_string")
  • Parâmetros

    Parameter Name

    Parameter type

    Required

    Description

    Nome do parâmetro

    Tipo de parâmetro

    Obrigatório

    Descrição

    timeexpression

    Objeto datetime

    Sim

    The format string. For more information, see Date and time format directives.

  • Resposta

    Retorna uma string de data e hora no formato especificado.

  • Exemplos

    Converte o valor do campo time para o formato especificado.

    • Log bruto

      time: 2019-06-03 2:41:26
      fmt: %Y/%m/%d %H-%M-%S
    • Transformation rule

      e_set("dt_strftime",dt_strftime(dt_parse(v("time")),v("fmt")))
    • Result

      time: 2019-06-03 2:41:26
      fmt: %Y/%m/%d %H-%M-%S
      dt_strftime: 2019/06/03 02-41-26

dt_strftimestamp

Converte um timestamp UNIX em uma string no formato especificado.

  • Sintaxe

    dt_strftimestamp(value, fmt="format_string", tz=None)
  • Parâmetros

    Parameter Name

    Parameter type

    Required

    Description

    Nome do parâmetro

    Tipo de parâmetro

    Obrigatório

    Descrição

    value

    String

    Sim

    The format string. For more information, see Date and time format directives.

    O timestamp UNIX a ser convertido.

    fmt

    String

    The time zone. The default value is None, which uses UTC. For more information, see Time zones.

  • Resposta

    Retorna uma string de data e hora no formato especificado.

  • Exemplos

    • Exemplo 1

      • Log bruto

        time: 1559500886
        fmt: %Y/%m/%d %H-%M-%S
      • Transformation rule

        e_set("dt_strftimestamp",dt_strftimestamp(v("time"),v("fmt")))
      • Result

        time: 1559500886
        fmt: %Y/%m/%d %H-%M-%S
        dt_strftimestamp: 2019/06/02 18-41-26
    • Example 2

      • Raw log

        time: 1559500886
        fmt: %Y/%m/%d %H-%M-%S
        tz: Asia/Tokyo
      • Transformation rule

        e_set("dt_strftimestamp",dt_strftimestamp(v("time"),v("fmt"),v("tz")))
      • Result

        dt_strftimestamp:2019/06/03 03-41-26
        fmt:%Y/%m/%d %H-%M-%S
        time:1559500886
        tz:Asia/Tokyo

dt_truncate

Trunca um valor ou o valor de uma expressão de tempo para uma granularidade de tempo especificada.

  • Sintaxe

    dt_truncate(value, unit='day')
  • Parâmetros

    Parameter Name

    Parameter type

    Required

    Description

    Nome do parâmetro

    Tipo de parâmetro

    Obrigatório

    Descrição

    value

    String, timestamp UNIX ou objeto datetime

    Sim

    The time granularity to truncate to. The default value is day. Optional values include second, minute, <num>_minute (for example, 5_minute, 19_minute, and 2_minute), hour, day, week, month, quarter, half_year, and year.

  • Resposta

    Retorna o valor truncado na granularidade de tempo especificada.

  • Exemplos

    • Exemplo 1

      • Log bruto

        time: 2019-06-03 2:41:26
        unit: year
      • Transformation rule

        e_set("dt_truncate",dt_truncate(v("time"),v("unit")))
      • Result

        time: 2019-06-03 2:41:26
        unit: year
        dt_truncate: 2019-01-01 00:00:00
    • Example 2

      • Raw log

        time: 2019-06-03 2:41:26
        unit: hour
      • Transformation rule

        e_set("dt_truncate",dt_truncate(v("time"),v("unit")))
      • Result

        time: 2019-06-03 2:41:26
        unit: hour
        dt_truncate: 2019-06-03 02:00:00

dt_add

Modifica um valor ou o valor de uma expressão de tempo com base em uma granularidade de tempo especificada.

  • Sintaxe

    dt_add(value, dt1=None, dt2=None, year(s)=None, month(s)=None, day(s)=None, hour(s)=None, minute(s)=None, second(s)=None, microsecond(s)=None, week(s)=None, weekday=None)
  • Parâmetros

    Parameter Name

    Parameter type

    Required

    Description

    Nome do parâmetro

    Tipo de parâmetro

    Obrigatório

    Descrição

    value

    String, timestamp UNIX ou objeto datetime

    Sim

    A expressão de data e hora.

    dt1

    String, timestamp UNIX ou objeto datetime

    Não

    A expressão de data e hora. O valor padrão é None.

    dt2

    String, timestamp UNIX ou objeto datetime

    Não

    • year: The year to replace the original year with. For example, year=2020. The default value is None.

    • years: The number of years to add. For example, years=1 adds one year to the original year.

    A expressão de data e hora. O valor padrão é None.

    year/years

    Number

    • day: The day to replace the original day with. For example, day=1. The default value is None.

    • days: The number of days to add. For example, days=1 adds one day to the original day.

    Não

    year: The year to replace the original year with. Por exemplo, year=2020. O valor padrão é None. years: O número de anos a adicionar. Por exemplo, years=1 adds one year to the original year.

    day/days

    • hour: The hour to replace the original hour with. For example, hour=1. The default value is None.

    • hours: The number of hours to add. For example, hours=1 adds one hour to the original hour.

    Number

    Não

    day: The day to replace the original day with. Por exemplo, day=1. O valor padrão é None. days: O número de dias a adicionar. Por exemplo, days=1 adds one day to the original day.

    • minute: The minute to replace the original minute with. For example, minute=1. The default value is None.

    • minutes: The number of minutes to add. For example, minutes=1 adds one minute to the original minute.

    hour/hours

    Number

    Não

    • second: The second to replace the original second with. For example, second=1. The default value is None.

    • seconds: The number of seconds to add. For example, seconds=1 adds one second to the original second.

    hour: The hour to replace the original hour with. Por exemplo, hour=1. O valor padrão é None. hours: O número de horas a adicionar. Por exemplo, hours=1 adds one hour to the original hour.

    minute/minutes

    Number

    • microsecond: Specifies the number of microseconds. For example, microsecond=1. The default value is None.

    • microseconds: The number of microseconds to add. microseconds=1 adds one microsecond to the original microsecond.

    Não

    minute: The minute to replace the original minute with. Por exemplo, minute=1. O valor padrão é None. minutes: O número de minutos a adicionar. Por exemplo, minutes=1 adds one minute to the original minute.

    second/seconds

    • week: The number of weeks to offset by. For example, week=1. The default value is None.

    • weeks: The number of weeks to add. weeks=1 adds one week to the original week.

    Number

    Não

    second: The second to replace the original second with. Por exemplo, second=1. O valor padrão é None. seconds: O número de segundos a adicionar. Por exemplo, seconds=1 adds one second to the original second.

    The weekday to offset to. For example, weekday=dt_MO(1). The default value is None.

  • Resposta

    Retorna o objeto datetime modificado.

  • Exemplos

    • Exemplo 1

      • Log bruto

        dt: 2018-10-10 1:2:3
        dt1: 2018-11-3 11:12:13
        dt2: 2018-10-1 10:10:10
      • Transformation rule

        e_set("dt_add",dt_add(dt_parse(v("dt")), dt1=dt_parse(v("dt1")), dt2=dt_parse(v("dt2"))))
      • Result

        dt:2018-10-10 1:2:3
        dt1:2018-11-3 11:12:13
        dt2:2018-10-1 10:10:10
        dt_add:2018-11-12 02:04:06
    • Example 2

      • Raw log

        dt: 2018-10-11 02:03:04
        year: 2019
      • Transformation rule

        e_set("dt_add", dt_add(dt_parse(v("dt")), year=ct_int(v("year"))))
      • Result

        dt:2018-10-11 02:03:04
        dt_add:2019-10-11 02:03:04
        year:2019

dt_MO

A value for the weekday parameter of the dt_add function that specifies an offset to a Monday.

  • Sintaxe

    dt_MO(Integer_or_negative)
  • Parâmetros

    Parameter

    Type

    Required

    Description

    Parâmetro

    Tipo

    Obrigatório

    The offset value. To pass a negative number, use op_neg(positive). For example, use op_neg(1) to represent -1.

  • Resposta

    Retorna um valor de deslocamento para dt_add.

  • Exemplos

    • Log bruto

      time: 2019-08-13 02:03:04
    • Transformation rule

      e_set("dt_MO",dt_add(v("time"),weekday=dt_MO(1)))
    • Result

      time: 2019-08-13 02:03:04
      dt_MO: 2019-08-19 02:03:04

dt_TU

A value for the weekday parameter of the dt_add function that specifies an offset to a Tuesday.

  • Sintaxe

    dt_TU(Integer_or_negative)
  • Parâmetros

    Parameter name

    Parameter Type

    Required

    Description

    Nome do parâmetro

    Tipo de parâmetro

    Obrigatório

    The offset value. To pass a negative number, use op_neg(positive). For example, use op_neg(1) to represent -1.

  • Resposta

    Retorna um valor de deslocamento para dt_add.

  • Exemplos

    For an example, see dt_MO.

dt_WE

A value for the weekday parameter of the dt_add function that specifies an offset to a Wednesday.

  • Sintaxe

    dt_WE(Integer_or_negative)
  • Parâmetros

    Parameter Name

    Type

    Required

    Description

    Nome do parâmetro

    Tipo

    Obrigatório

    The offset value. To pass a negative number, use op_neg(positive). For example, use op_neg(1) to represent -1.

  • Resposta

    Retorna um valor de deslocamento para dt_add.

  • Exemplos

    For an example, see dt_MO.

dt_TH

A value for the weekday parameter of the dt_add function that specifies an offset to a Thursday.

  • Sintaxe

    dt_TH(Integer_or_negative)
  • Parâmetros

    Parameter Name

    Parameter Type

    Required

    Description

    Nome do parâmetro

    Tipo de parâmetro

    Obrigatório

    The offset value. To pass a negative number, use op_neg(positive). For example, use op_neg(1) to represent -1.

  • Resposta

    Retorna um valor de deslocamento para dt_add.

  • Exemplos

    For an example, see dt_MO.

dt_FR

A value for the weekday parameter of the dt_add function that specifies an offset to a Friday.

  • Sintaxe

    dt_FR(Integer_or_negative)
  • Parâmetros

    Parameter Name

    Parameter type

    Required

    Description

    Nome do parâmetro

    Tipo de parâmetro

    Obrigatório

    The offset value. To pass a negative number, use op_neg(positive). For example, use op_neg(1) to represent -1.

  • Resposta

    Retorna um valor de deslocamento para dt_add.

  • Exemplos

    For an example, see dt_MO.

dt_SA

A value for the weekday parameter of the dt_add function that specifies an offset to a Saturday.

  • Sintaxe

    dt_SA(Integer_or_negative)
  • Parâmetros

    Parameter Name

    Parameter Type

    Required

    Description

    Nome do parâmetro

    Tipo de parâmetro

    Obrigatório

    The offset value. To pass a negative number, use op_neg(positive). For example, use op_neg(1) to represent -1.

  • Resposta

    Retorna um valor de deslocamento para dt_add.

  • Exemplos

    For an example, see dt_MO.

dt_SU

A value for the weekday parameter of the dt_add function that specifies an offset to a Sunday.

  • Sintaxe

    dt_SU(Integer_or_negative)
  • Parâmetros

    Parameter name

    Parameter Type

    Required

    Description

    Nome do parâmetro

    Tipo de parâmetro

    Obrigatório

    The offset value. To pass a negative number, use op_neg(positive). For example, use op_neg(1) to represent -1.

  • Resposta

    Retorna um valor de deslocamento para dt_add.

  • Exemplos

    For an example, see dt_MO.

dt_astimezone

Converte um valor ou o valor de uma expressão de tempo em um objeto datetime em um fuso horário específico.

  • Sintaxe

    dt_astimezone(value, tz, reset=False)
  • Parâmetros

    Parameter

    Type

    Required

    Description

    Parâmetro

    Tipo

    Obrigatório

    Descrição

    value

    String, timestamp UNIX ou objeto datetime

    Sim

    The time zone. The default value is None. For more information, see Time zones.

    O valor ou a expressão de tempo.

    tz

    String

    Não

  • Resposta

    Retorna o objeto datetime convertido no fuso horário especificado.

  • Exemplos

    • Exemplo 1

      • Log bruto

        time: 2019-06-03 2:41:26
        tz: UTC
      • Transformation rule

        e_set("dt_astimezone",dt_astimezone(dt_parse(v("time")), v("tz")))
      • Result

        time: 2019-06-03 2:41:26
        tz: UTC
        dt_astimezone: 2019-06-03 02:41:26+00:00
    • Example 2

      • Raw log

        time: 2019-06-01 10:10:10+10:00
        tz: Asia/Tokyo
      • Transformation rule

        e_set("dt_astimezone",dt_astimezone(v("time"), v("tz"),reset=True))
      • Result

        time: 2019-06-01 10:10:10+10:00
        tz: Asia/Tokyo
        dt_astimezone: 2019-06-01 10:10:10+09:00
    • Example 3

      • Raw log

        time: 2019-06-01 10:10:10+08:00
        tz: Asia/Tokyo
      • Transformation rule

        e_set("dt_astimezone",dt_astimezone(v("time"), v("tz"),reset=False))
        e_set("dt_astimezone_true",dt_astimezone(v("time"), v("tz"),reset=True))
      • Result

        dt_astimezone:2019-06-01 11:10:10+09:00
        dt_astimezone_true:2019-06-01 10:10:10+09:00
        time:2019-06-01 10:10:10+08:00
        tz:Asia/Tokyo

dt_diff

Obtém a diferença entre dois valores ou valores de expressão de tempo em uma granularidade específica.

  • Sintaxe

    dt_diff(value1, value2, unit='second', normalize='floor')
  • Parâmetros

    Parameter name

    Parameter type

    Required

    Description

    Nome do parâmetro

    Tipo de parâmetro

    Obrigatório

    Descrição

    value1

    String, timestamp UNIX ou objeto datetime

    Sim

    O valor ou a expressão de tempo.

    value2

    String, timestamp UNIX ou objeto datetime

    Sim

    The unit for the returned difference. The default value is second. Other valid values include microsecond, millisecond, minutes, hours, and day.

    O valor ou a expressão de tempo.

    unit

    String

    Não

    • floor (default): Rounds the number down.

    • int: Returns the integer part.

    • round: Rounds the number to N decimal places.

    • ceil: Rounds the number up.

  • Resposta

    Retorna a diferença entre dois valores datetime na granularidade especificada.

  • Exemplos

    • Exemplo 1: Calcula a diferença entre os valores dos campos time1 e time2 em segundos.

      • Log bruto

        time1: 2018-10-1 10:10:10
        time2: 2018-10-1 10:10:10
      • Transformation rule

        e_set("diff",dt_diff(v("time1"), v("time2")))
      • Result

        time1: 2018-10-1 10:10:10
        time2: 2018-10-1 10:10:10
        diff: 0
    • Example 2: Calculates the difference between the values of the time1 and time2 fields in seconds.

      • Raw log

        time1: 2018-10-1 11:10:10
        time2: 2018-10-1 10:10:10
      • Transformation rule

        e_set("diff",dt_diff(v("time1"), v("time2")))
      • Result

        time1: 2018-10-1 11:10:10
        time2: 2018-10-1 10:10:10
        diff: 3600
    • Example 3: Calculates the difference between the values of the time1 and time2 fields in microseconds.

      • Raw log

        time1: 2018-10-1 11:10:11
        time2: 2018-10-1 10:10:10
        unit: microsecond
      • Transformation rule

        e_set("diff",dt_diff(v("time1"), v("time2"),v("unit")))
      • Result

        diff:3601000000
        time1:2018-10-1 11:10:11
        time2:2018-10-1 10:10:10
        unit:microsecond
    • Example 4: Calculates the difference between the values of the time1 and time2 fields in minutes and rounds the result down.

      • Raw log

        time1: 2018-10-1 11:11:59
        time2: 2018-10-1 10:10:00
        unit: minute
        normalize: floor
      • Transformation rule

        e_set("diff", dt_diff(v("time1"), v("time2"), v("unit"), v("normalize")))
      • Result

        diff:61
        normalize:floor
        time1:2018-10-1 11:11:59
        time2:2018-10-1 10:10:00
        unit:minute
    • Example 5: Calculates the difference between the values of the time1 and time2 fields in seconds and rounds the result down.

      • Raw log

        time1: 10:00:00
        time2: 11:00:00
        unit: second
        normalize: floor
      • Transformation rule

        e_set("diff", dt_diff(v("time1"), v("time2"), v("unit"), v("normalize")))
      • Result

        diff:-3600
        normalize:floor
        time1:10:00:00
        time2:11:00:00
        unit:second