Create a time variable in perl
source link: https://www.codesd.com/item/create-a-time-variable-in-perl.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Create a time variable in perl
I want to create a variable that will store hardcoded hours and minutes value. Rest stuff like min, day, date, year should be current date and time. How can I do this? I tried timelocal, localtime and many others, but they didn't work.
Unless I'm missing something, you indeed use localtime
, as in perldoc: http://perldoc.perl.org/functions/localtime.html
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
Then, if you want to stick to using the broken-down components, you could overwrite whichever variables you want to "fix":
$hour = $my_hardcoded_hour;
$min = $my_hardcoded_minute;
If instead you need to translate this back to "seconds since the epoch" (Jan 1, 1970, 12:00AM GMT) format, you need the Time::Local
package:
http://perldoc.perl.org/Time/Local.html
use Time::Local;
$epoch_current_time_with_fixed_hour_min =
timelocal($sec, $my_hardcoded_minutes, $my_hardcoded_hour, $mday, $mon, $year);
Related Articles
SAS: create a time ID variable with a program (instead of using the point-and-click system)
PHP Create a new variable for each time a link in an iframe changes
Creating a file name using variables in Perl
Is there a new variable created each time in a loop?
Create a date variable from the time (with SAS 9.3)
How do I create a new variable for a list each time a new key is entered?
Archive :: Zip Can not create a Zip object in Perl
Is it a good practice to export variables in Perl?
Creating a time series from a netcdf file for specific coordinates
Creating with time series from a dataset with missing values
How to create a multi-variable & ldquo; Ts & rdquo; Object in R?
Create a new variable defined only for a subset of data using `dplyr`
Scope of variables in perl
Is there a way to create your own @@ variable in SQL Server?
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK