Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Q&A

Welcome to the Power Users community on Codidact!

Power Users is a Q&A site for questions about the usage of computer software and hardware. We are still a small site and would like to grow, so please consider joining our community. We are looking forward to your questions and answers; they are the building blocks of a repository of knowledge we are building together.

Comments on How to set the default time format in Linux Debian.

Parent

How to set the default time format in Linux Debian.

+2
−0

How to set the default time format in Linux? For example to set the format the date command outputs when run with no parameters.

History
Why does this post require attention from curators or moderators?
You might want to add some details to your flag.
Why should this post be closed?

0 comment threads

Post
+2
−0

You can define the LC_TIME environment variable. In ~/.profile if you start you session in a login shell or else ~/.bashrc, put

export LC_TIME=ru_RU.UTF-8

For example,

% LC_TIME=ru_RU.UTF-8 date
Сб 07 окт 2023 13:39:21 CEST

will make the output format be in Russian,

That only works if you already have that locale enabled (or, better said, generated), which you can check with locale -a. If it is not generated yet, find the corresponding line in /etc/locale.gen, remove the # from it and run locale-gen.

In a desktop environment, there might be a corresponding option in the localization settings.

All the environment variables heeded by date specifically are found in the POSIX specification.

And the locale section lists the variable in more details, as well as which other functions must respect it.

There is an expectation, but not a guarantee, that time related programs and functions will respect that variable.

History
Why does this post require attention from curators or moderators?
You might want to add some details to your flag.

1 comment thread

Don't understand that. I was asking about the time format. How is that bind to a locale? Shouldn't th... (4 comments)
Don't understand that. I was asking about the time format. How is that bind to a locale? Shouldn't th...
H_H‭ wrote about 1 year ago · edited about 1 year ago

Don't understand that. I was asking about the time format. How is that bind to a locale? Shouldn't that be local independent?

I want to use a format similar to ISO8601 regardless of where i am. How to set the time format as %Y-%m-%d_%T?

Quasímodo‭ wrote about 1 year ago

Well, each locale does have a different time format.

$ LC_TIME=en_US.utf8 date +%x~%X
10/09/2023~01:08:12 PM
$ LC_TIME=ru_RU.utf8 date +%x~%X
09.10.2023~13:08:17

The question does not match what you are asking in comments. Also note that where you are ≠ where your computer is configured to be. These details matter and the lack thereof lead to a different answer than the one you apparently wanted.

H_H‭ wrote about 1 year ago · edited about 1 year ago

"The question does not match what you are asking in comments"

My question is how to configure the datetime format. With that i mean, how can i set a specific format, for example a string that is used in strftime(). I don't see a difference from the comment to the original question. It is very confusing for me that that should depend on a locale.

Yes where you are ≠ where your computer is configured to be. I should have said "regardless of where my computer is configured to be". sorry.

Does that mean i have to generate every possible locale, check every possible locale if the format matches what i want, and if there is no locale that has this time format, i am out of luck?

Quasímodo‭ wrote about 1 year ago · edited about 1 year ago

My question is how to configure the datetime format.

Isn't that simply what you wrote in the other comment? I.e. date +%Y-%m-%d_%T?

Does that mean i have to generate every possible locale, check every possible locale if the format matches what i want, and if there is no locale that has this time format, i am out of luck?

If you want a plain date to return that specific format, it's impossible without verifying each locale as you said, because, as per the specification I linked to:

STDOUT

When no formatting operand is specified, the output in the POSIX locale shall be equivalent to specifying:

date "+%a %b %e %H:%M:%S %Z %Y"