Display time in 12 hr format


 
Thread Tools Search this Thread
Contact Us Post Here to Contact Site Administrators and Moderators Display time in 12 hr format
# 1  
Old 07-25-2016
Display time in 12 hr format

Write a script named time that displays the time in standard 12-hour format, rather than 24-hour format. Allow the user to give a -m option to get 24-hour format. For example:
> date
Sun Feb 10 10:56:50 CST 2008

> time
10:56 AM

> date
Sun Feb 10 21:57:07 CST 2008

> time
9:57 PM

> time -m
21:57



Moderator's Comments:
Mod Comment Do not post classroom or homework problems in the main forums. Homework and coursework questions can only be posted in this forum under special homework rules.

Please review the rules, which you agreed to when you registered, if you have not already done so.

More-than-likely, posting homework in the main forums has resulting in a forum infraction. If you did not post homework, please explain the company you work for and the nature of the problem you are working on.

If you did post homework in the main forums, please review the guidelines for posting homework and repost.

Thank You.

The UNIX and Linux Forums.

Last edited by RudiC; 07-25-2016 at 03:04 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Calculate Time diff in milli milliseconds(Time format : HH:MM:SS,NNN)

Hi All, I have one file which contains time for request and response. I want to calculate time difference in milliseconds for each line. This file can contain 10K lines. Sample file with 4 lines. for first line. Request Time: 15:23:45,255 Response Time: 15:23:45,258 Time diff... (6 Replies)
Discussion started by: Raza Ali
6 Replies

2. UNIX for Beginners Questions & Answers

Hour display format

Hello Sir/Madam, I'm using Putty utility to run a shell script. I found HOUR display in two positions in UNIX. Is it possible to display in four positions? File name example: my file name is: HourlyData_20160708_1400.txt I'm in the process of comparing current date and time with the file... (15 Replies)
Discussion started by: V1l1h1
15 Replies

3. Shell Programming and Scripting

Hange display format

I have a file , the file content will be modified regularly , its structure as below, the lines are begins with "A" and "B" . #vi file1 this is testing file A aaaaa B bbbbb A ccccc B ddddd A eeeee B fffff A ggggg B hhhhh I would like to have a script to use the... (3 Replies)
Discussion started by: ust3
3 Replies

4. Shell Programming and Scripting

Long list file display different time format.

Hi Gurus, I have some weird issue. when using ls -l the result shows different time format: -rw-r--r-- 1 abc gourp1 3032605576 Jun 14 2013 abc -rw-rw-r-- 1 abc gourp1 1689948832 Aug 10 06:22 abc one display 2013 which is year; another one displays 06:22 which is time. ... (4 Replies)
Discussion started by: ken6503
4 Replies

5. Shell Programming and Scripting

Changing display format

Hi, My file cat a.txt Sat Nov 27 00:02:00 2010 00:02:00 Usr 27: Login by edi on batch. (452) 00:02:09 Usr 27: Logout by on batch. (453) 00:02:09 Usr 27: Login by edi on batch. (452) 00:02:22 Usr 27: Logout by on batch. (453) 00:02:22 Usr 27: Login by edi on batch.... (3 Replies)
Discussion started by: ganeshanbu
3 Replies

6. UNIX for Advanced & Expert Users

Need to display complete format of ps

Hi All, For one of my script I need to get the complete format of PS as result. Actually in our application, we have to execute some program to get the data for batch files. Now there is some java script is running on unix for this which is not identifiable. I want to know how to... (2 Replies)
Discussion started by: nishank.jain
2 Replies

7. Shell Programming and Scripting

List files and display last modify time in a particular format

hi everyone, can someone suggest how i can list the contents of a directory and display their corresponding last modify time in the format yyyymmddhhmm? thanks in advance! (16 Replies)
Discussion started by: Deanne
16 Replies

8. UNIX for Dummies Questions & Answers

Date Display Format

Hello People, How can I display the date in a continuous format along with the time as below : 20091001_154547 i.e yyyymmdd_hhmmss format. Thanks. (3 Replies)
Discussion started by: sushant172
3 Replies

9. Shell Programming and Scripting

Convert Epoch time format to normal date time format in the same file

I have a file named "suspected" with series of line like these : {'protocol': 17, 'service': 'BitTorrent KRPC', 'server': '219.78.120.166', 'client_port': 52044, 'client': '10.64.68.44', 'server_port': 8291, 'time': 1226506312L, 'serverhostname': ''} {'protocol': 17, 'service': 'BitTorrent... (3 Replies)
Discussion started by: rk4k
3 Replies
Login or Register to Ask a Question