CONTENT
  • CHANGES
Szukaj
counter

#top Date/Time


code / perl / datetime

#top Predefined Constants


No Predefined Constants here.





#top Datatypes / MACROS


No Datatypes here.





#top Date/Time Functions


#top gettimeofday


Documentacja online: perldoc.perl.org | www.tutorialspoint.com

Deklaracja funkcji gettimeofday() jest następująca:


Powiązane:

Opis:
description

Example:
zawartość pliku gettimeofday.pl
SELECT ALL
#!/usr/bin/perl -w

use strict;      # force definations for all vars an subroutines
use warnings;    # force check of unset variables in expressions
use diagnostics; # give var/code line number on faults

use Time::HiRes qw(gettimeofday); # gettimeofday



if ($#ARGV+1<0) {
	print("Usage: $0\n");
	exit(1);
}

my ($sec, $usec)=gettimeofday();
print""(\$sec, \$usec)=gettimeofday(): \$sec=$sec, \$usec=$usec\n");

my $timestamp=$sec+$usec/1e6;
print""\$timestamp=\$sec+\$usec/1e6: \$timestamp=$timestamp\n");

Aby zobaczyć jak działa program należy go uruchomić bez argumentów:
/home/local/code/perlcode/datetime/gettimeofday.pl
program wyświetli stosowne informacje o sposobie działania:
($sec, $usec)=gettimeofday(): $sec=1378838802, $usec=347074
$timestamp=$sec+$usec/1e6: $timestamp=1378838802.34707



#top gmtime


Documentacja online: perldoc.perl.org | www.tutorialspoint.com

Deklaracja funkcji gmtime() jest następująca:
gmtime EXPR

Powiązane:
gmtime(), localtime(), strftime(),

Opis:
description



#top localtime


Documentacja online: perldoc.perl.org | www.tutorialspoint.com

Deklaracja funkcji localtime() jest następująca:
localtime EXPR

Powiązane:
gmtime(), localtime(), strftime(),

Opis:
description



#top mktime


Documentacja online: perldoc.perl.org | www.tutorialspoint.com

Deklaracja funkcji mktime() jest następująca:


Powiązane:
mktime(), str2time(),

Opis:
description

Example:
zawartość pliku mktime.pl
SELECT ALL
#!/usr/bin/perl -w

use strict;      # force definations for all vars an subroutines
use warnings;    # force check of unset variables in expressions
use diagnostics; # give var/code line number on faults

use POSIX qw(mktime strftime);



my ($YYYY, $mm, $dd, $HH, $MM, $SS);
my ($time);



if ($#ARGV+1<6) {
	print("Usage: $0 <YYYY> <mm> <dd> <HH> <MM> <SS>\n");
	print("Examples:\n");
	print("       $0 2001 02 03 04 05 06\n");
	exit(1);
}

$YYYY=int($ARGV[0]);
$mm=int($ARGV[1]);
$dd=int($ARGV[2]);
$HH=int($ARGV[3]);
$MM=int($ARGV[4]);
$SS=int($ARGV[5]);

if ($YYYY>1900) { $YYYY=$YYYY-1900; }
if ($mm>0) { $mm=$mm-1; }

# mktime(sec, min, hour, mday, mon, year, wday = 0, yday = 0, isdst = 0)
$time=mktime( $SS, $MM, $HH, $dd, $mm, $YYYY );
if (defined($time)) { print("$0: \$time=mktime( $SS, $MM, $HH, $dd, $mm, $YYYY ): \$time=$time if (defined($time)): Sucessful mktime(), datetime=".strftime('%Y/%m/%d %H:%M:%S',localtime($time))."\n"); }
else                { print("$0: \$time=mktime( $SS, $MM, $HH, $dd, $mm, $YYYY ): \$time=$time if (defined($time)): else: Unable to mktime().\n"); }

Aby zobaczyć jak działa program należy go uruchomić bez argumentów:
/home/local/code/perlcode/datetime/mktime.pl
program wyświetli informacje o sposobie uruchamiania programu:
Usage: /home/local/code/perlcode/datetime/mktime.pl <YYYY> <mm> <dd> <HH> <MM> <SS>
Examples:
       /home/local/code/perlcode/datetime/mktime.pl 2001 02 03 04 05 06


jako argument wywołania programu można podać analogiczne jak poniżej argumenty:
/home/local/code/perlcode/datetime/mktime.pl 2001 02 03 04 05 06
rezultat będzie zależny od podanego argumentu wywołania programu:
/home/local/code/perlcode/datetime/mktime.pl: $time=mktime( 6, 5, 4, 3, 1, 101 ): $time=981169506 if (defined(981169506)): Sucessful mktime(), datetime=2001/02/03 04:05:06



#top str2time


Documentacja online: perldoc.perl.org | www.tutorialspoint.com

Deklaracja funkcji str2time() jest następująca:


Powiązane:
mktime(), str2time(),

Opis:
description

Example:
zawartość pliku str2time.pl
SELECT ALL
#!/usr/bin/perl -w

use strict;      # force definations for all vars an subroutines
use warnings;    # force check of unset variables in expressions
use diagnostics; # give var/code line number on faults

use POSIX qw(strftime);
use Date::Parse; # for str2time(),



my ($timestring, $timestamp, $timeform);



if ($#ARGV+1<1) {
	print("Usage: $0 <string-date>\n");
	print("Examples:\n");
	print("       $0 \"2001/02/03 04:05:06\"\n");
	print("       $0 \"Feb 03 04:05:06\"\n");
	print("       $0 \"Sat,  3 Feb 2001 01:02:03 +0100 (CET)\"\n");
	exit(1);
}

$timestring=$ARGV[0];
$timestamp=str2time($timestring);
print""$0: \$timestamp=str2time($timestring): \$timestamp=$timestamp\n");
$timeform=strftime('%Y/%m/%d %H:%M:%S',localtime($timestamp));
print""$0: \$timeform=strftime('\%Y/\%m/\%d \%H:\%M:\%S', localtime($timestamp)): \$timeform=$timeform\n");

Aby zobaczyć jak działa program należy go uruchomić bez argumentów:
/home/local/code/perlcode/datetime/str2time.pl
program wyświetli informacje o sposobie uruchamiania programu:
Usage: /home/local/code/perlcode/datetime/str2time.pl <string-date>
Examples:
       /home/local/code/perlcode/datetime/str2time.pl "2013/09/10 01:02:02"
       /home/local/code/perlcode/datetime/str2time.pl "Sep 10 10:12:15"
       /home/local/code/perlcode/datetime/str2time.pl "Fri,  1 Feb 2013 10:46:24 +0100 (CET)"

jako argument wywołania programu można podać analogiczne jak poniżej argumenty:
/home/local/code/perlcode/datetime/str2time.pl "2013/09/10 01:02:02"
/home/local/code/perlcode/datetime/str2time.pl "Sep 10 10:12:15"
/home/local/code/perlcode/datetime/str2time.pl "Fri,  1 Feb 2013 10:46:24 +0100 (CET)"
rezultat będzie zależny od podanego argumentu wywołania programu:
/home/local/code/perlcode/datetime/str2time.pl: 1378767722=str2time(2013/09/10 01:02:02): strftime('%Y/%m/%d %H:%M:%S', localtime(1378767722))=2013/09/10 01:02:02

/home/local/code/perlcode/datetime/str2time.pl: 1378800735=str2time(Sep 10 10:12:15): strftime('%Y/%m/%d %H:%M:%S', localtime(1378800735))=2013/09/10 10:12:15

/home/local/code/perlcode/datetime/str2time.pl: 1359711984=str2time(Fri,  1 Feb 2013 10:46:24 +0100 (CET)): strftime('%Y/%m/%d %H:%M:%S', localtime(1359711984))=2013/02/01 10:46:24



#top strftime


Documentacja online: perldoc.perl.org | www.tutorialspoint.com

Deklaracja funkcji strftime() jest następująca:


Powiązane:
gmtime(), localtime(), strftime(),

Opis:
description

Example:
zawartość pliku strftime.pl
SELECT ALL
#!/usr/bin/perl -w

use strict;      # force definations for all vars an subroutines
use warnings;    # force check of unset variables in expressions
use diagnostics; # give var/code line number on faults

use POSIX qw (strftime);



my ($argtime, $inttime, $strtime);
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst);



if ($#ARGV+1<=0) {
	print("Usage: $0 <int-value-timestamp>\n");
	print("Examples:\n");
	print("       $0 1234567890\n");
	exit(1);
}

$argtime=$ARGV[0];
$inttime=int($argtime);

$strtime=strftime('%Y/%m/%d %H:%M:%S',localtime($inttime));
print""$0: strftime('\%Y/\%m/\%d \%H:\%M:\%S', localtime($inttime)=$strtime\n");

($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($inttime);
$strtime=strftime('%Y/%m/%d %H:%M:%S',$sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst);
print""$0: strftime('\%Y/\%m/\%d \%H:\%M:\%S', localtime($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=$strtime\n");

$strtime=strftime('%Y/%m/%d %H:%M:%S', localtime());
print""$0: strftime('\%Y/\%m/\%d \%H:\%M:\%S', localtime())=$strtime\n");



$strtime=strftime('%Y/%m/%d %H:%M:%S',gmtime($inttime));
print""$0: strftime('\%Y/\%m/\%d \%H:\%M:\%S', gmtime($inttime)=$strtime\n");

($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = gmtime($inttime);
$strtime=strftime('%Y/%m/%d %H:%M:%S',$sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst);
print""$0: strftime('\%Y/\%m/\%d \%H:\%M:\%S', gmtime($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=$strtime\n");

$strtime=strftime('%Y/%m/%d %H:%M:%S', gmtime());
print""$0: strftime('\%Y/\%m/\%d \%H:\%M:\%S', gmtime())=$strtime\n");

Aby zobaczyć jak działa program należy go uruchomić bez argumentów:
/home/local/code/perlcode/datetime/strftime.pl
program wyświetli informacje o sposobie uruchamiania programu:
Usage: /home/local/code/perlcode/datetime/strftime.pl <int-value-timestamp>

jako argument wywołania programu można podać analogiczne jak poniżej argumenty:
/home/local/code/perlcode/datetime/strftime.pl 1234567890
rezultat będzie zależny od podanego argumentu wywołania programu:
/home/local/code/perlcode/datetime/strftime.pl: strftime('%Y/%m/%d %H:%M:%S', localtime(1234567890)=2009/02/14 00:31:30
/home/local/code/perlcode/datetime/strftime.pl: strftime('%Y/%m/%d %H:%M:%S', localtime(30,31,0,14,1,109,6,44,0)=2009/02/14 00:31:30
/home/local/code/perlcode/datetime/strftime.pl: strftime('%Y/%m/%d %H:%M:%S', localtime())=2013/10/10 07:51:51
/home/local/code/perlcode/datetime/strftime.pl: strftime('%Y/%m/%d %H:%M:%S', gmtime(1234567890)=2009/02/13 23:31:30
/home/local/code/perlcode/datetime/strftime.pl: strftime('%Y/%m/%d %H:%M:%S', gmtime(30,31,23,13,1,109,5,43,0)=2009/02/13 23:31:30
/home/local/code/perlcode/datetime/strftime.pl: strftime('%Y/%m/%d %H:%M:%S', gmtime())=2013/10/10 05:51:51



#top time


Documentacja online: perldoc.perl.org | www.tutorialspoint.com

Deklaracja funkcji time() jest następująca:


Powiązane:

Opis:
description

Example:
zawartość pliku time.pl
SELECT ALL
#!/usr/bin/perl -w

use strict;      # force definations for all vars an subroutines
use warnings;    # force check of unset variables in expressions
use diagnostics; # give var/code line number on faults



my ($nowtime);



if ($#ARGV+1<0) {
	print("Usage: $0\n");
	exit(1);
}

$nowtime=time();
print""$0: \$nowtime=time(): \$nowtime=$nowtime\n");

Aby zobaczyć jak działa program należy go uruchomić bez argumentów:
/home/local/code/perlcode/datetime/time.pl
program wyświetli stosowne informacje o sposobie działania:
/home/local/code/perlcode/datetime/time.pl: $nowtime=time(): $nowtime=1381363514




Zmodyfikowany ostatnio: 2013/11/20 22:42:16 (10 lat temu), textsize: 12,3 kB, htmlsize: 29,3 kB

Zapraszam do komentowania, zgłaszania sugestii, propozycji, własnych przykładów, ...
Dodaj komentarzKomentarze użytkowników