`
standalone
  • 浏览: 595937 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

Date/Time处理函数总结 [To Do]

 
阅读更多
几种我所用到的用来处理日期,时间的函数总结。

Perl

1. localtime

     # 0 1 2 3 4 5 6 7 8
    ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =
    localtime(time);


If parameter is not provides, it will use current time. Note the $year returned contains the number of years since 1900, to get a 4-digit year you need:

$year += 1900;

And the $mon starts from 0 to 11.


2. strftime

     use POSIX qw(strftime);
    $now_string = strftime "%a %b %e %H:%M:%S %Y", localtime;
    # or for GMT formatted appropriately for your locale:
    $now_string = strftime "%a %b %e %H:%M:%S %Y", gmtime;




Strftime 时间域  ( 这个和 date 的命令的字符格式是一样的), 参见

http://www.php-oa.com/2010/08/21/perl-strftime.html

% H 小时(00..23)
% I 小时(01..12)
% k 小时(0..23)
% l 小时(1..12)
% M 分(00..59)
% p 显示出AM或PM
% r 时间(hh:mm:ss AM或PM),12小时
% s 从1970年1月1日00:00:00到目前经历的秒数
% S 秒(00..59)
% T 时间(24小时制)(hh:mm:ss)
% X 显示时间的格式(%H:%M:%S)
% Z 时区 日期域
% a 星期几的简称( Sun..Sat)
% A 星期几的全称( Sunday..Saturday)
% b 月的简称(Jan..Dec)
% B 月的全称(January..December)
% c 日期和时间( Mon Nov 8 14:12:46 CST 1999)
% d 一个月的第几天(01..31)
% D 日期(mm/dd/yy)
% h 和%b选项相同
% j 一年的第几天(001..366)
% m 月(01..12)
% w 一个星期的第几天(0代表星期天)
% W 一年的第几个星期(00..53,星期一为第一天)
% x 显示日期的格式(mm/dd/yy)
% y 年的最后两个数字( 1999则是99)
% Y 年(例如:1970,1996等)

3. time

Returns the number of non-leap seconds since whatever time the system considers to be the epoch, suitable for feeding to gmtime and localtime. On most systems the epoch is 00:00:00 UTC, January 1, 1970

4. Date::Calc

Quite useful. Some methods I frequently use:

  Add_Delta_Days
      ($year,$month,$day) =
      Add_Delta_Days($year,$month,$day,
                     $Dd);


  Today
      ($year,$month,$day) = Today([$gmt]);

  Now
      ($hour,$min,$sec) = Now([$gmt]);

  Delta_Days
      $Dd = Delta_Days($year1,$month1,$day1,
                       $year2,$month2,$day2);

5. Date::Parse

http://search.cpan.org/~gbarr/TimeDate-2.30/lib/Date/Parse.pm
Used to parse date string into time values.

str2time(DATE [, ZONE])

    str2time parses DATE and returns a unix time value, or undef upon failure. ZONE, if given, specifies the timezone to assume when parsing if the date string does not specify a timezone.
strptime(DATE [, ZONE])

    strptime takes the same arguments as str2time but returns an array of values ($ss,$mm,$hh,$day,$month,$year,$zone). Elements are only defined if they could be extracted from the date string. The $zone element is the timezone offset in seconds from GMT. An empty array is returned upon failure.

Java
参考:http://tianlovv.iteye.com/blog/402116

JavaScript

创建一个日期对象:

var objDate=new Date([arguments list]);

参数形式有以下5种:

   new Date("month dd,yyyy hh:mm:ss");
   new  Date("month dd,yyyy");
   new  Date(yyyy,mth,dd,hh,mm,ss);
   new Date(yyyy,mth,dd);
   new Date(ms);

需要注意最后一种形式,参数表示的是需要创建的时间和GMT时间1970年1月1日之间相差的毫秒数。各种函数的含义如下:

month:用英文表示月份名称,从January到December

mth:用整数表示月份,从0到11

dd:表示一个月中的第几天,从1到31

yyyy:四位数表示的年份

hh:小时数,从0(午夜)到23(晚11点)

mm:分钟数,从0到59的整数

ss:秒数,从0到59的整数

ms:毫秒数,为大于等于0的整数

参考:
http://www.cnblogs.com/east-liujie/archive/2006/10/21/535784.html

Sybase
http://wang-zhi-peng2007.iteye.com/blog/1199091
分享到:
评论

相关推荐

    javascript函数的解释

    javascript函数的解释,解释了具体函数的功能,一、函数JavaScript函数集合 1.document.write(""); 输出语句 2.JS中的注释为// 3.传统的HTML文档顺序是:document->html->(head,body) 4.一个浏览器窗口中的DOM顺序是:...

    C++大学教程,一本适合初学者的入门教材(part1)

    2.17 do/while重复结构 2.18 break和continue语句 2.19 逻辑运算符 2.20 混淆相等(.==)与赋值(=)运算符 2.21 结构化编程小结 2.22 有关对象的思考:确定问题中的对象 小结 术语 自测练习 自测练习答案 ...

    VBSCRIP5 -ASP用法详解

    Time 函数 返回反映当前系统时间的日期子类型的变体。 Timer 函数 返回时经子夜 12:00 AM 后的秒数。 TimeSerial 函数 返回含有指定时分秒时间的日期子类型的变体。 TimeValue 函数 返回含有时间的日期子类型的...

    PHP基础教程 是一个比较有价值的PHP新手教程!

    所有变量都是局部变量,为了使得定义的函数中可以使用外部变量,使用global语句。而你要将该变量的作用范围限制在该函数之内,使用static语句。 $g_var = 1 ; // 全局范围 function test() { global $g_var; // 这样...

    《ASP网络程序设计》实验指导书(网站建设与维护&网络程序设计)

    VBScript内部函数可分为:转换函数、字符串函数、日期和时间函数、数学函数和检验函数。 1.转换函数 VBScript对Variant变量一般会根据需要自动转换成合适的数据类型;但有时,自动转换有可能造成数据类型不匹配错误...

    VBSCRIPT中文手册

    Time 函数 返回反映当前系统时间的日期子类型的变体。 Timer 函数 返回时经子夜 12:00 AM 后的秒数。 TimeSerial 函数 返回含有指定时分秒时间的日期子类型的变体。 TimeValue 函数 返回含有时间的日期子类型的...

    vb Script参考文档

    Time 函数 返回反映当前系统时间的日期子类型的变体。 Timer 函数 返回时经子夜 12:00 AM 后的秒数。 TimeSerial 函数 返回含有指定时分秒时间的日期子类型的变体。 TimeValue 函数 返回含有时间的日期子类型的...

    VB编程资源大全(英文源码 函数)

    <END><br>21,frmmain.zip This will calculate your midterm and final grade average.<END><br>22,taxes.zip This program computes weekly payroll, current earnings, year to date earnings FICA tax, ...

    MYSQL v4.1中文参考手册(CHM)

    6.2.2 Date 和 Time 类型 6.2.2.1 Y2K 问题和日期类型 6.2.2.2 DATETIME、DATE 和 TIMESTAMP 类型 6.2.2.3 TIME 类型 6.2.2.4 YEAR 类型 6.2.3 字符串类型 6.2.3.1 CHAR 和 VARCHAR 类型 6.2.3.2 BLOB...

    uboott移植实验手册及技术文档

    在文件的最后加入Nand Flash的初始化函数,该函数在后面Nand Flash的操作都要用到。 u-boot运行到第2阶段会进入start_armboot()函数。其中nand_init()函数是对nand flash的最 初初始化函数。nand_init()函数在两个...

    VBScript 语言参考

    Time 函数 返回反映当前系统时间的日期子类型的变体。 Timer 函数 返回时经子夜 12:00 AM 后的秒数。 TimeSerial 函数 返回含有指定时分秒时间的日期子类型的变体。 TimeValue 函数 返回含有时间的日期子类型的...

    VBScript 语言参考中文手册CHM

    Time 函数 返回反映当前系统时间的日期子类型的变体。 Timer 函数 返回时经子夜 12:00 AM 后的秒数。 TimeSerial 函数 返回含有指定时分秒时间的日期子类型的变体。 TimeValue 函数 返回含有时间的日期子类型的...

    windows下配置apache+php+mysql时出现问题的处理方法

    2. 设置好配置文件,发现会报一个date函数的关于时区的警告,把php中的date.timezone加上date.timezone = Asia/Shanghai; 3. 老是报Call to undefined function openssl_get_publickey,把php.ini中的extension=...

    Lotus公式语言函数简介

    @DeleteDocument 在代理中运行时此函数时,删除正在被处理的文档 @DeleteField 在代理中运行该函数,@DeleteField 将删除指定的域 @DialogBox 弹出一个对话框,用指定的表单显示当前的文档 @Do 从左到右计算表达式,...

    最全的oracle常用命令大全.txt

    Connected to an idle instance. SQL> startup^C SQL> startup ORACLE instance started. 2、在双机环境下 要想启动或关闭ORACLE系统必须首先切换到root用户,如下 su - root a、启动ORACLE系统 hareg -y ...

    C++大学教程,一本适合初学者的入门教材(part2)

    2.17 do/while重复结构 2.18 break和continue语句 2.19 逻辑运算符 2.20 混淆相等(.==)与赋值(=)运算符 2.21 结构化编程小结 2.22 有关对象的思考:确定问题中的对象 小结 术语 自测练习 自测练习答案 ...

    MySQL 5.1官方简体中文参考手册

    11.3.1. DATETIME、DATE和TIMESTAMP类型 11.3.2. TIME类型 11.3.3. YEAR类型 11.3.4. Y2K事宜和日期类型 11.4. String类型 11.4.1. CHAR和VARCHAR类型 11.4.2. BINARY和VARBINARY类型 11.4.3. BLOB和TEXT类型 11.4.4...

    tinytime::alarm_clock:小于1kb的简单日期和时间格式化程序

    tinytime导出单个函数,该函数返回模板对象。 该对象具有单个方法render ,该方法采用Date并返回包含渲染数据的字符串。 import tinytime from 'tinytime' ; const template = tinytime ( 'The time is {h}:{mm}:{...

    ZendFramework中文文档

    9.4.3. Basic Zend_Date Operations Common to Many Date Parts 9.4.3.1. List of Date Parts 9.4.3.2. List of Date Operations 9.4.4. Comparing Dates 9.4.5. Getting Dates and Date Parts 9.4.6. Working ...

    MySQL 5.1中文手冊

    13.4.4. SAVEPOINT和ROLLBACK TO SAVEPOINT语法 13.4.5. LOCK TABLES和UNLOCK TABLES语法 13.4.6. SET TRANSACTION语法 13.4.7. XA事务 13.5. 数据库管理语句 13.5.1. 账户管理语句 13.5.2. 表维护语句 13.5.3. SET...

Global site tag (gtag.js) - Google Analytics