• perl 获取系统时间


    最近需要将字符串转换成时间,找了下资料,实战如下,发现时timelocal费了些时间

    strftime也可在 c / c++ / awk / php 中使用,用法基本一致。

    这个也不错

    $time = strftime("%Y-%m-%d %H:%M:%S", localtime($time));

    print "$time ";
    print str2time($time);

    use POSIX qw(strftime);
    use Time::Local;
    use HTTP::Date;
    
    
    my $time = "{"date":"2013-06-24","time":"01:53:40"}";  
    print "$time 
    ";
    
    print str2time($time);
    
    formattime($time);
    
    sub formattime{
        my ($srctime) = @_;
        my ($year,$mon,$day,$hour,$min,$sec) = $srctime=~ /.+?(d+)-(d+)-(d+).+?(d+):(d+):(d+)/ ;
        print "
     $year,$mon,$day,$hour,$min,$sec 
    ";
        
        $time = str2time("$year-$mon-$day $hour:$min:$sec");
        #print "$time 
    ";
        
        #print strftime("%Y%m%d%H%M%S",localtime($time));
        return $time;
    }
    use strict;
    use POSIX;
    use Time::Local;
    
    
    my $time = time();
    print "$time 
    ";
    
    my @time = localtime($time);
    print "@time 
    ";
    
    $time = strftime("%Y-%m-%d %H:%M:%S", localtime($time));
    print "$time 
    ";
    
    my ($year,$mon,$day,$hour,$min,$sec) = $time=~/(d+)-(d+)-(d+) (d+):(d+):(d+)/ ;
    print "$year,$mon,$day,$hour,$min,$sec 
    ";
    
    $time = timelocal($sec,$min,$hour,$day,$mon,$year);
    print "$time 
    ";
  • 相关阅读:
    7.Layout布局(tabs、accordion、layout)
    6.form表单四种提交方式
    5.form表单验证
    4.easyloader.js文件的作用
    3.window窗口
    2.panel面板
    1.messager消息提示框
    2017-10-5-Python
    2017-9-24-Linux移植:ubuntu server 16.04无法联网&无法apt-get update解决
    2017-9-17-EDFA
  • 原文地址:https://www.cnblogs.com/xiaoxiaocaicai/p/3151799.html
Copyright © 2020-2023  润新知