Operating System - HP-UX
1833187 Members
2725 Online
110051 Solutions
New Discussion

Re: Change the format of date

 
Tan jianmin
Occasional Advisor

Change the format of date

Dear all,how can I change the format of date.I want to set the format of date to "yymmdd".

Best regards
Tanjm
11 REPLIES 11
Laurent Menase
Honored Contributor

Re: Change the format of date

in what occasion?
on which output?
Laurent Menase
Honored Contributor

Re: Change the format of date

do you just mean
date +%y%m%d
Tan jianmin
Occasional Advisor

Re: Change the format of date

Dear Laurent Menase:
Thanks a lot for your quickly reply.
Use date +%y%m%d command just change the output once.I want to make it effective permanently.
Laurent Menase
Honored Contributor

Re: Change the format of date

but for what command output?
only date?
ls?
Tan jianmin
Occasional Advisor

Re: Change the format of date

The output of date %y%m%d command is below.
# date +%y%m%d
090914

When I use date command again,the output is below.
# date
Mon Sep 14 16:55:36 EAT 2009

I want to use date command to get the output just like date +%y%m%d command.How do I change the format of the date.

Laurent Menase
Honored Contributor

Re: Change the format of date

you must use localdef to change the LC_TIME table definition
Tan jianmin
Occasional Advisor

Re: Change the format of date

Thanks,I'll try it.
Laurent Menase
Honored Contributor

Re: Change the format of date

to display the current one use
locale -k LC_TIME
Roland Piette
Regular Advisor

Re: Change the format of date

Hi

Another option, create an alias in your user profile. Add this line :

alias date='date +%y%m%d'

You can try it online.

If you want to get back the original output (without unalias it) type de command date between quotes.

'date'

Regards,
Roland
Dennis Handly
Acclaimed Contributor

Re: Change the format of date

>Roland: If you want to get back the original output type the command date between quotes.

You can also quote first char: \date
Roland Piette
Regular Advisor

Re: Change the format of date

Thanks Dennis for this variant.
Roland