The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Unix Arithmatic operation issue , datatype issue thambi Shell Programming and Scripting 23 02-19-2008 07:19 AM
File timestamp issue on HP servers siddaonline UNIX for Advanced & Expert Users 5 07-04-2007 11:09 AM
timestamp Minguccio75 SUN Solaris 4 02-21-2007 04:06 AM
timestamp rocker40 UNIX for Dummies Questions & Answers 3 10-09-2003 09:09 AM
ftp timestamp Henrik UNIX for Dummies Questions & Answers 4 05-03-2003 09:19 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 10-22-2008
chriss_58 chriss_58 is offline
Registered User
  
 

Join Date: May 2008
Posts: 41
Timestamp issue in perl script language

Hello all,

I have a problem with timestamps in perl.

Suppose we have the following timestamp:
Wed Oct 22 13:20:41 2008 This timestamp is produced with 'localtime' function.
How can i convert the above timestamp to the format:
081022132041

08=2008
10=Oct

Thank you...

Last edited by chriss_58; 10-22-2008 at 07:42 AM..
  #2 (permalink)  
Old 10-22-2008
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,723
Do you want to do this from C - then look at the strftime function?

code snippet:
Code:
char output[80]={0x0};
time_t lt=time(NULL);
char *fmt="%y%m%d%H%%M%S";

strftime(output, sizeof(output), fmt, localtime(&lt);
printf("%s\n", output);
  #3 (permalink)  
Old 10-22-2008
chriss_58 chriss_58 is offline
Registered User
  
 

Join Date: May 2008
Posts: 41
I am sorry i forgot to tell you that i am using perl...
  #4 (permalink)  
Old 10-22-2008
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,723
Code:
perl -e 'print strftime "%y%m%d%H%%M%S\n", localtime($mtime);'
perl one liner
  #5 (permalink)  
Old 10-22-2008
SFNYC SFNYC is offline
Registered User
  
 

Join Date: Jun 2008
Location: New York City
Posts: 95
Code:
perl -e 'print strftime "%y%m%d%H%%M%S\n", localtime($mtime);'
Too many % signs in that one and he may need to use Posix.

Code:
perl -e 'use POSIX qw(strftime);print strftime "%y%m%d%H%M%S\n", localtime();'

081022102542
  #6 (permalink)  
Old 10-22-2008
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,723
IF you notice I copied that bad date format from the C app above. Thanks, good catch.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 01:02 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0