[an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive]
 
[an error occurred while processing this directive] [an error occurred while processing this directive]
Skåne Sjælland Linux User Group - http://www.sslug.dk Home   Subscribe   Mail Archive   Forum   Calendar   Search
MhonArc Date: [Date Prev] [Date Index] [Date Next]   Thread: [Date Prev] [Thread Index] [Date Next]   MhonArc
 

Re: [PERL] DATETIME fra perl



On 9 Mar 2000, Kristian Bjørnskov wrote:

> HP Openview bruger et tidsformat der ser sådan ud:
> 
> Thu Mar  9 08:49:01 2000
> 
> Jeg skal have disse lagt ind i en MySQL database som DATETIME, men jeg kan ikke
> rigtigt få konverteret på en smart måde. Jeg har lavet et workaround med date
> på en linux dåse, men det er altså ikke særlig portabelt, og det ser heller
> ikke særligt pænt ud.
> 
> Det jeg altså gerne vil have perl til er at lave nedenstående (lidt smartere):
>
> ------
> 
> sslug@sslug perl]$ ./timetest.pl 
> 2000-03-09 08:49:01

#!/home/value/apps/perl -w
use strict;
use Date::Parse;
use Date::Format 'time2str';

print time2str("%Y-%m-%d %T",str2time("Thu Mar  9 08:49:01 2000")),"\n";


#!/home/value/apps/perl -w
use strict;
use Date::Parse;

my $time = str2time("Thu Mar  9 08:49:01 2000");

my ($year,$mon,$day,$hour,$minute,$second)
     = (localtime($time))[5,4,3,2,1,0];

printf "%04i-%02i-%02i %02i:%02i:%02i\n",
    $year+1900,$mon+1,$day,$hour,$minute,$second;


 - ask

-- 
ask bjoern hansen - <http://www.netcetera.dk/~ask/>



 
Home   Subscribe   Mail Archive   Index   Calendar   Search

 
 
Questions about the web-pages to <www_admin>. Last modified 2005-08-10, 19:52 CEST [an error occurred while processing this directive]
This page is maintained by [an error occurred while processing this directive]MHonArc [an error occurred while processing this directive] # [an error occurred while processing this directive] *