Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Date command conversion date prompt date in Linux: what to do with illegal time format error

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces the Linux date command conversion date prompt date: illegal time format error how to do, the article is very detailed, has a certain reference value, interested friends must read it!

Preface

Many shell scripts need to print different formats of time or date, and to perform actions based on time and date. Latency is usually used to provide a period of waiting time during script execution. Dates can be printed in multiple formats, or you can use the command to set a fixed format. In UNIX-like systems, the date is stored as an integer of the number of seconds that have elapsed since 00:00:00 Universal Standard time (UTC) on January 1, 1970.

Grammar

Date (option) (parameter)

But recently encountered a problem in the use, let's take a look at the detailed introduction.

Problem: error in running the date command

Date-j-f "a b d T Z Y" Sat Sep 29 11:33:00 CST 2018 "+ s"

Error report:

Failed conversion of ``Sat Sep 29 11:33:00 CST 2018 'using format ``% a% b% d% T% Z% Y''date: illegal time formatusage: date [- jnRu] [- d dst] [- r seconds] [- t west] [- v [+ | -] valu [mm]]. [- f fmt date | [[mm] dd] HH] MM [[cc] yy] [.ss]] [+ format]

Command description:

1. The format of the date string to be converted by murf, which corresponds to the format of the following string

% a week

% b month

% T: minutes: seconds

% Z time zone

% Y year

2. Date% s to be converted, converted to seconds

Solution:

Check whether the LANG is in Chinese or English through locale. If the date and month is in English, switch to English. Otherwise, switch to Chinese.

Switch to English: export LANG= "en_US.UTF-8"

Switch to Chinese: export LANG= "zh_CN.UTF-8"

Reason:

The system is divided into Chinese and English. When-f parses the date string, the month and week must be in Chinese or English of the corresponding system.

For example: 1. Execute the command date-j-f "a b d T Z Y" Sat Sep 29 11:33:00 CST 2018 "+ s"

two。

View the language of the current system

3.

Date string is English, change LANG to English

Export LANG= "en_US.UTF-8"

4.

After changing the language, the command to convert the date was successfully executed.

The above is all the contents of the article "date command conversion date prompt date: what to do with illegal time format errors in Linux". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report