- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Converting TimeStamp
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-25-2004 01:34 AM
03-25-2004 01:34 AM
Converting TimeStamp
Is there a way to covert a unix timestamp to '%Y%m%d %H%M'
for eg 1080145459 must result to "20040324182419" or "2004/03/24/18:24:19"
I have tried the following and works well, but cannot get the date format that I require.
echo "od1080145459=Y|adb | tr -d '\011' and the result is
2004 Mar 24 18:24:19
Many Thanks
Chris
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-25-2004 01:49 AM
03-25-2004 01:49 AM
Re: Converting TimeStamp
BEGIN{dadate["Jan"]="01";dadate["Feb"]="02"; dadate["Mar"]="03";dadate["Apr"]="0
4";dadate["May"]="05";dadate["Jun"]="06";dadate["Jul"]="07";dadate["Aug"]="08";
dadate["Sep"]="09";dadate["Oct"]="10";dadate["Nov"]="11";dadate["Dec"]="12";}
{print $1"/"dadate[$2]"/"$3"/"$4 }
Then pipe what you have so far (the 2004 Mar 24 18:24:19 ) through the script using | awk -f date.awk
That would do it.
Oz
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-25-2004 01:58 AM
03-25-2004 01:58 AM
Re: Converting TimeStamp
interesting adb use. It must have something to do with localization.
Anyway, I wrote a little C program. May need some adjustment for your output format.
See attachment.
JP.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-25-2004 02:50 AM
03-25-2004 02:50 AM
Re: Converting TimeStamp
If the remaining challenge is translate month names to number, might I suggest the awk index function? for example:
echo "2004 Mar 24 18:24:19" | awk '{m=index("xxJanFebMarAprMayJunJulSepOctNovDec",$2)/3; print m"/"$3"/"$1}'
Hein.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-25-2004 02:55 AM
03-25-2004 02:55 AM
Re: Converting TimeStamp
timestamp.pl
---------------------------------
#!/usr/bin/perl -w
use strict;
sub do_1_timestamp
{
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($_[0]);
printf("%04d%02d%02d%02d%02d\n",$year + 1900,$mon + 1,$mday,$hour,$min);
}
while ($#ARGV >= 0)
{
do_1_timestamp($ARGV[0]);
shift;
}
------------------------------------------
TS=1080145459
TM=$(timestamp.pl ${TS})
echo "Timestamp for ${TS} -> ${TM}"
The above script uses the localtime() function which takes into account timezone and daylight saving time. You might choose to use the gmtime() function which report UTC time. I intentionally grabbed all the values returned from localtime() so that you can modify the printf to as complicated an output as you like. Note: $year is number of years since 1900 and $mon ranges from 0 to 11 -- just like the C counterparts.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-25-2004 03:06 AM
03-25-2004 03:06 AM
Re: Converting TimeStamp
Tue Jul 22 07:00:45 2003
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-25-2004 03:06 AM
03-25-2004 03:06 AM
Re: Converting TimeStamp
Clay, right. Perl is proabbly the ultimate solution.
btw... 'shift' byy default operates on ARGV so the main loop in you example can be simplified from:
while ($#ARGV >= 0)
{
do_1_timestamp($ARGV[0]);
shift;
}
to (a less readbale perhaps):
do_1_timestamp($ts) while ($ts=shift);
Cheers,
Hein.
perl -e 'while ($#ARGV>=0) { print $ARGV[0],"\n"; shift }' aap noot mies
vs
perl -e 'while ($_=shift) { print $_,"\n"}' aap noot mies