2025-02-10T05:29:29

This commit is contained in:
2025-02-10 05:29:29 +09:00
parent e00dd1bfbf
commit 6f1a75f466
45 changed files with 69 additions and 145 deletions

68
docs/13_date_time.md Normal file
View File

@@ -0,0 +1,68 @@
# 날짜와 시간
## time
1970-01-01 이후부터의 경과 시간을 초 단위로 반환합니다.
```perl
$epoch = time();
```
## localtime
매개 변수로 시간을 전달할 수 있으며, 생략되면 현재 시간이 사용됩니다. localtime()을 스칼라로 받으면 시간을 나타내는 문자열 표현이되고, 배열로 받으면 9개의 요소를 가진 배열이 됩니다.
```perl
my $now = localtime();
print "$now\n"; # Thu Feb 11 15:19:03 2021
```
```perl
$epoch = time();
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($epoch);
```
- sec : 초. 0~59
- min : 분. 0 ~ 59
- hour : 시. 0 ~ 24
- mday : 일. 1 ~ 31
- mon : 월. 0 ~ 11
- year : 년. 1900년부터.
- wday : 요일. 일요일부터.
- yday : 1월 1일 이후의 날짜 수.
- isdst : 일광절약제 적용 여부.
```perl
print &date_format."\n";
sub date_format{
my @weeks = qw(일 월 화 수 목 금 토);
my $time = (defined $_[0]) ? $_[0] : time();
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($time);
$mon += 1;
$year += 1900;
$wday = $weeks[$wday];
return "$year년 $mon월 $mday일 $wday요일 $hour시 $min분 $sec초";
}
```
```perl
print &ymdhms."\n";
sub ymdhms{
my $time = (defined $_[0]) ? $_[0] : time();
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($time);
$mon += 1;
$year += 1900;
sprintf ("%04d-%02d-%02d %02d:%02d:%02d", $year, $mon, $mday, $hour, $min, $sec);
}
```
## gmtime
UTC 시간입니다. localtime()과 같은 방식으로 사용하면 됩니다. 다만, UTC시간이므로, $isdst는 항상 0입니다.
```perl
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = gmtime($time);
```
#