AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • Início
  • system&network
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • Início
  • system&network
    • Recentes
    • Highest score
    • tags
  • Ubuntu
    • Recentes
    • Highest score
    • tags
  • Unix
    • Recentes
    • tags
  • DBA
    • Recentes
    • tags
  • Computer
    • Recentes
    • tags
  • Coding
    • Recentes
    • tags
Início / unix / Perguntas / 733074
Accepted
ka3ak
ka3ak
Asked: 2023-01-26 06:10:34 +0800 CST2023-01-26 06:10:34 +0800 CST 2023-01-26 06:10:34 +0800 CST

Não é possível definir a data em um formato específico

  • 772

Não há problema em obter a data com o comando abaixo:

$ date '+%d%m%y %H%M%S.%N'
250123 170411.504761505

No entanto, configurá-lo usando o mesmo formato não é possível:

sudo date '+%d%m%y %H%M%S.%N' -u -s "250123 170411.504761505"
date: invalid date ‘250123 170411.504761505’

Parece que delimitadores entre horas, minutos e segundos são necessários. Por que? A página do manual não parece mencioná-lo.

Ele menciona:

%H     hour (00..23)
%M     minute (00..59)
%S     second (00..60)

Portanto, se houver 6 dígitos na string de origem, ela poderá analisá-la sem problemas IMO.

Achei que a nano-parte confundiu, mas não:

$sudo date '+%d%m%y %H%M%S' -u -s "250123 170411"
date: invalid date ‘250123 170411’
bash
  • 1 1 respostas
  • 53 Views

1 respostas

  • Voted
  1. Best Answer
    Freddy
    2023-01-26T08:42:08+08:002023-01-26T08:42:08+08:00

    Sua string de formato é usada apenas para formatar a string de saída e não para analisar a string de entrada.

    Os formatos de entrada de calendário e hora suportados são descritos nas subseções da seção 29 "Formatos de entrada de data" do manual de informações de data GNU ( online ):

    29.2 Calendar date items
    ========================
    
    A “calendar date item” specifies a day of the year.  It is specified
    differently, depending on whether the month is specified numerically or
    literally.  All these strings specify the same calendar date:
    
         1972-09-24     # ISO 8601.
         72-9-24        # Assume 19xx for 69 through 99,
                        # 20xx for 00 through 68.
         72-09-24       # Leading zeros are ignored.
         9/24/72        # Common U.S. writing.
         24 September 1972
         24 Sept 72     # September has a special abbreviation.
         24 Sep 72      # Three-letter abbreviations always allowed.
         Sep 24, 1972
         24-sep-72
         24sep72
    
       The year can also be omitted.  In this case, the last specified year
    is used, or the current year if none.  For example:
    
         9/24
         sep 24
    
       Here are the rules.
    
       For numeric months, the ISO 8601 format ‘YEAR-MONTH-DAY’ is allowed,
    where YEAR is any positive number, MONTH is a number between 01 and 12,
    and DAY is a number between 01 and 31.  A leading zero must be present
    if a number is less than ten.  If YEAR is 68 or smaller, then 2000 is
    added to it; otherwise, if YEAR is less than 100, then 1900 is added to
    it.  The construct ‘MONTH/DAY/YEAR’, popular in the United States, is
    accepted.  Also ‘MONTH/DAY’, omitting the year.
    
       Literal months may be spelled out in full: ‘January’, ‘February’,
    ‘March’, ‘April’, ‘May’, ‘June’, ‘July’, ‘August’, ‘September’,
    ‘October’, ‘November’ or ‘December’.  Literal months may be abbreviated
    to their first three letters, possibly followed by an abbreviating dot.
    It is also permitted to write ‘Sept’ instead of ‘September’.
    
       When months are written literally, the calendar date may be given as
    any of the following:
    
         DAY MONTH YEAR
         DAY MONTH
         MONTH DAY YEAR
         DAY-MONTH-YEAR
    
       Or, omitting the year:
    
         MONTH DAY
    
    
    
    29.3 Time of day items
    ======================
    
    A “time of day item” in date strings specifies the time on a given day.
    Here are some examples, all of which represent the same time:
    
         20:02:00.000000
         20:02
         8:02pm
         20:02-0500      # In EST (U.S. Eastern Standard Time).
    
       More generally, the time of day may be given as ‘HOUR:MINUTE:SECOND’,
    where HOUR is a number between 0 and 23, MINUTE is a number between 0
    and 59, and SECOND is a number between 0 and 59 possibly followed by ‘.’
    or ‘,’ and a fraction containing one or more digits.  Alternatively,
    ‘:SECOND’ can be omitted, in which case it is taken to be zero.  On the
    rare hosts that support leap seconds, SECOND may be 60.
    
    [...]
    

    Por exemplo, esses formatos de entrada funcionariam:

    $ sudo date -us "23-01-25 17:04:11.504761505"
    Wed 25 Jan 2023 05:04:11 PM UTC
    

    ou

    $ sudo date -us "25 Jan 2023 17:04:11.504761505"
    Wed 25 Jan 2023 05:04:11 PM UTC
    

    ou (este com -debugopção)

    $ sudo date -us "01/25/23 17:04:11.504761505" --debug
    date: warning: value 1 has less than 4 digits. Assuming MM/DD/YY[YY]
    date: parsed date part: (Y-M-D) 0023-01-25
    date: parsed time part: 17:04:11.504761505
    date: input timezone: TZ="UTC0" environment value or -u
    date: warning: adjusting year value 23 to 2023
    date: using specified time as starting value: '17:04:11'
    date: starting date/time: '(Y-M-D) 2023-01-25 17:04:11'
    date: '(Y-M-D) 2023-01-25 17:04:11' = 1674666251 epoch-seconds
    date: timezone: Universal Time
    date: final: 1674666251.504761505 (epoch-seconds)
    date: final: (Y-M-D) 2023-01-25 17:04:11 (UTC)
    date: final: (Y-M-D) 2023-01-25 17:04:11 (UTC+00)
    Wed 25 Jan 2023 05:04:11 PM UTC
    
    • 1

relate perguntas

  • exportar variáveis ​​​​env programaticamente, via stdout do comando [duplicado]

  • Problema estranho ao passar variáveis ​​do arquivo de texto

  • Enquanto a linha lê mantendo os espaços de escape?

  • ordem de substituição de processos `te` e `bash`

  • Execute um script muito lento até que seja bem-sucedido

Sidebar

Stats

  • Perguntas 205573
  • respostas 270741
  • best respostas 135370
  • utilizador 68524
  • Highest score
  • respostas
  • Marko Smith

    Possível firmware ausente /lib/firmware/i915/* para o módulo i915

    • 3 respostas
  • Marko Smith

    Falha ao buscar o repositório de backports jessie

    • 4 respostas
  • Marko Smith

    Como exportar uma chave privada GPG e uma chave pública para um arquivo

    • 4 respostas
  • Marko Smith

    Como podemos executar um comando armazenado em uma variável?

    • 5 respostas
  • Marko Smith

    Como configurar o systemd-resolved e o systemd-networkd para usar o servidor DNS local para resolver domínios locais e o servidor DNS remoto para domínios remotos?

    • 3 respostas
  • Marko Smith

    apt-get update error no Kali Linux após a atualização do dist [duplicado]

    • 2 respostas
  • Marko Smith

    Como ver as últimas linhas x do log de serviço systemctl

    • 5 respostas
  • Marko Smith

    Nano - pule para o final do arquivo

    • 8 respostas
  • Marko Smith

    erro grub: você precisa carregar o kernel primeiro

    • 4 respostas
  • Marko Smith

    Como baixar o pacote não instalá-lo com o comando apt-get?

    • 7 respostas
  • Martin Hope
    user12345 Falha ao buscar o repositório de backports jessie 2019-03-27 04:39:28 +0800 CST
  • Martin Hope
    Carl Por que a maioria dos exemplos do systemd contém WantedBy=multi-user.target? 2019-03-15 11:49:25 +0800 CST
  • Martin Hope
    rocky Como exportar uma chave privada GPG e uma chave pública para um arquivo 2018-11-16 05:36:15 +0800 CST
  • Martin Hope
    Evan Carroll status systemctl mostra: "Estado: degradado" 2018-06-03 18:48:17 +0800 CST
  • Martin Hope
    Tim Como podemos executar um comando armazenado em uma variável? 2018-05-21 04:46:29 +0800 CST
  • Martin Hope
    Ankur S Por que /dev/null é um arquivo? Por que sua função não é implementada como um programa simples? 2018-04-17 07:28:04 +0800 CST
  • Martin Hope
    user3191334 Como ver as últimas linhas x do log de serviço systemctl 2018-02-07 00:14:16 +0800 CST
  • Martin Hope
    Marko Pacak Nano - pule para o final do arquivo 2018-02-01 01:53:03 +0800 CST
  • Martin Hope
    Kidburla Por que verdadeiro e falso são tão grandes? 2018-01-26 12:14:47 +0800 CST
  • Martin Hope
    Christos Baziotis Substitua a string em um arquivo de texto enorme (70 GB), uma linha 2017-12-30 06:58:33 +0800 CST

Hot tag

linux bash debian shell-script text-processing ubuntu centos shell awk ssh

Explore

  • Início
  • Perguntas
    • Recentes
    • Highest score
  • tag
  • help

Footer

AskOverflow.Dev

About Us

  • About Us
  • Contact Us

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve