How to display century in UNIX.

Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers How to display century in UNIX.
# 1  
Old 08-29-2011
How to display century in UNIX.


I wanted to display Century in Unix.

I tried with date +"%C"

Which is displaying Mon Aug 29 12:54:54 BST 2011. (Used capital C).
and when used date +"%c"

Displaying Mon Aug 29 12:54:33 2011. (used Small c)

But i want century (21) to get displayed. Please let me know how can i do that.
# 2  
Old 08-29-2011
Which UNIX? They're not all the same.

%C ought to work in many of them but apparently not in yours.
# 3  
Old 08-29-2011
Please show the output of:
uname -a

For more modern unix implemenatations, this is more of a locale thing than anything else.
LC_ALL=POSIX && date +%C

# 4  
Old 08-30-2011
Version is
SunOS bfu226a002 5.9 Generic_118558-13 sun4u sparc SUNW,Sun-Fire-V240
# 5  
Old 08-30-2011
Does this produce the correct output:
/usr/xpg4/bin/date +"%C"

From the Solaris 10 date manpage:

If the argument begins with +, the output of date is the result of passing format and the current time to strftime(). date uses the conversion specifications listed on the strftime(3C) manual page, with the conversion specification for %C determined by whether /usr/bin/date or /usr/xpg4/bin/date is used:
# 6  
Old 08-30-2011

actully already tried with
/usr/xpg4/bin/date +"%C" which gave me 20.
need to get present century i.e. 21.
So used below query:

echo "`/usr/xpg4/bin/date +'%C + 1' | bc`"

got the required result.

Thanks a lot. Smilie

Last edited by radoulov; 08-30-2011 at 12:23 PM.. Reason: Code tags.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

UNIX script to display the filename

Hi All How to answer the below interview question.. With a path and filename of "/mydir1/mydir2/mydir3/myfilenane.dat" write a UNIX script to display the filename (2 Replies)
Discussion started by: shumail
2 Replies

2. AIX

New to Unix - display issue

new to the forums hope is this the right area to post this, I have 4 IBM servers (inherited) and all of them are connecting through a KVM. Probelm is all the servers are fuzzy on the monitor. I have tried switching multiple monitors and all get the same effect no matter if they are wide screen or... (4 Replies)
Discussion started by: Setnaro
4 Replies

3. UNIX for Dummies Questions & Answers

Display the content of the unix file

cat is the normal unix command to display the content of a file. Is there any program to display the content of the file. If there is, then can you send me the code. (5 Replies)
Discussion started by: vedanjalig
5 Replies

4. Shell Programming and Scripting

How to display two dimensional array in UNIX

Hi all, Please help me out how to read and display two dimensional array elements in unix. EX: 1 2 3 4 (1 Reply)
Discussion started by: eswarcs
1 Replies

5. Shell Programming and Scripting

Display a Graphic from a Unix program on a Pc how?

An interesting puzzle. I run character based compiled C-Programs in a Unix environment on PCs in a Window. I want to be able to call up and display in a separate window a picture of a product called by a Unix shell script from within my Unix program. Ideally I would like to have a script that... (4 Replies)
Discussion started by: Barry Staples
4 Replies

6. UNIX for Dummies Questions & Answers

How Can I Display Unix Path All The Time

How Can I Display Unix Path All The Time currently my profile look like this # @(#)local.profile 1.8 99/03/26 SMI stty istrip PATH=/usr/bin:/usr/ucb:/etc:. export PATH # If possible, start the windows system # if ; then if then if ; then ... (1 Reply)
Discussion started by: murli1200
1 Replies

7. Solaris

Extract century from date (Solaris platform)

Hi , I want the date in the following format(Solaris platform) CCYYMMDD:HHSS I am facing problems in extracting century from the date. I tried the following options. `date '+%cc%y%m%d:%H%S` but the Output is (Thu Feb 09 02:28:21 2006c060209:0221). I think this... (1 Reply)
Discussion started by: u449064
1 Replies

8. UNIX for Dummies Questions & Answers

Cant display korean file on Unix

I got a korean file from AS/400 machine and save it in a AIX Server (using ftp command). The file is converting to CCSID 949 (korean character) and CCSID 13488 (unicode) respectively. It is no problem to view 2 file by using F-Secure SSH Client (command more)from a window Xp (locale : Korean).... (0 Replies)
Discussion started by: hahahafung
0 Replies

9. Shell Programming and Scripting

How to display fractions of a second in UNIX

How can I display fraction of a second using Date command? (2 Replies)
Discussion started by: GNMIKE
2 Replies

10. UNIX for Dummies Questions & Answers

display the timestamp of a server UNIX

I can't find the command shell UNIX to display the timestamp of the current date. It's not an option of the commande date. (3 Replies)
Discussion started by: nicolas
3 Replies
Login or Register to Ask a Question