Thread datum konvertierung: unix format in human format (5 answers)
Opened by misterx at 2005-04-10 22:26

renee
 2005-04-11 11:16
#53691 #53691
User since
2003-08-04
14371 Artikel
ModeratorIn
[Homepage] [default_avatar]
Lesbar -> Timestamp:

Code: (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#! /usr/bin/perl

use strict;
use warnings;
use Time::Local;

my $string = 'time: Tue Apr 21 11:50:33 2005';
my $timestamp = get_time($string);
print $timestamp,"\n";

sub get_time{
 my ($string) = @_;
 my %months = (Jan => 0, Feb => 1, Mar => 2, Apr => 3,
               May => 4, Jun => 5, Jul => 6, Aug => 7,
               Sep => 8, Oct => 9, Nov => 10,Dec => 11,);

 my (undef,undef,undef,$mon,$day,$hr,$min,$sec,$year) = split(/[:\s]/,$string);
 my $time = timelocal($sec,$min,$hr,$day,$months{$mon},$year-1900);
 return $time;
}


Timestamp -> lesbar:

Code: (dl )
1
2
3
my $timestamp = '1114077033';
my $readable = localtime($timestamp);
print $readable,"\n";


edit: Vergleich bekommst Du beim timestamp->lesbar mit Datum1 eq Datum2 hin, bei lesbar->timestamp mit Time1 == Time2.\n\n

<!--EDIT|renee|1113204106-->
OTRS-Erweiterungen (http://feature-addons.de/)
Frankfurt Perlmongers (http://frankfurt.pm/)
--

Unterlagen OTRS-Workshop 2012: http://otrs.perl-services.de/workshop.html
Perl-Entwicklung: http://perl-services.de/

View full thread datum konvertierung: unix format in human format