Displaying Japanese time on a server in oversea

Top Japanese page




Overview

on the servers in outside of Japan, use JST time for update time.

Flow

  1. Get file update time
  2. Convert modified epoch time to date time information
  3. Display it

A sample code

 my $offset_from_gmt = 9;
 my $mtime = (stat("$file"))[9];
 my ($min,$hour,$mday,$mon,$year) = 
         (gmtime($mtime+$offset_from_gmt*3600))[1 .. 5];
 printf("%s/%s/%s %02s:%02s",$mon+1,$mday,$year+1900,$hour,$min);

Description of the code

 my $offset_from_gmt = 9;

Set offset hours from GMT. In Japan time case, it is +9 hours. Negative value can be specified.

 my $mtime = (stat("$file"))[9];

Get file update time from stat function.

 my ($min,$hour,$mday,$mon,$year) = 
         (gmtime($mtime+$offset_from_gmt*3600))[1 .. 5];

Convert $mtime into date time information with adding offset to adjust Japan time. In this example, throwing away unused return values.

 printf("%s/%s/%s %02s:%02s",$mon+1,$mday,$year+1900,$hour,$min);

Display the date information as your favorite format. $year use 0 as 1900. So add 1900. And month indicate 0 in Janurary. So add 1.