xui.Date


静态类

静态方法

add    diff    format    get    getText    getTimSpanEnd    getTimSpanStart    getWeek    offsetTimeZone    parse    

add ( date,datepart,count )    [函数源代码]

在基准时间戳加上一个时间段.

返回值: Object, the result Date Object.

参数:

  • date [必需参数] : Date Object, 基准时间戳.

  • datepart [必需参数] : String, 时间段单位. 'ms','s','n','h','d','ww','m','q','y','de' or 'c'.

  • count [必需参数] : Number, 时间段的值.

示例:

- 代码运行js文件 多比手机组态云平台API代码查看器 - 官网

  1. var date = xui.Date,d = date.parse('1/1/2000'),arr = []; 

  2. arr.push(_.serialize(date.add(d,'ms',600))); 

  3. arr.push(_.serialize(date.add(d,'s',1))); 

  4. arr.push(_.serialize(date.add(d,'n',1))); 

  5. arr.push(_.serialize(date.add(d,'h',1))); 

  6. arr.push(_.serialize(date.add(d,'d',1))); 

  7. arr.push(_.serialize(date.add(d,'ww',1))); 

  8. arr.push(_.serialize(date.add(d,'m',1))); 

  9. arr.push(_.serialize(date.add(d,'q',1))); 

  10. arr.push(_.serialize(date.add(d,'y',1))); 

  11. arr.push(_.serialize(date.add(d,'de',1))); 

  12. arr.push(_.serialize(date.add(d,'c',1))); 

  13. alert(arr.join('\n'))

 

^

diff ( startdate,enddate,datepart,firstDayOfWeek )    [函数源代码]

获取两个时间戳之间的时间段.

返回值: Number

参数:

  • startdate [必需参数] : Date, 开始时间.

  • enddate [必需参数] : Date, 结束时间.

  • datepart [必需参数] : String, 时间段单位. 'ms','s','n','h','d','ww','m','q','y','de' or 'c'.

  • firstDayOfWeek [可选参数] : 每周的第一天的编号. 默认为 0.

示例:

- 代码运行js文件 多比手机组态云平台API代码查看器 - 官网

  1. var date = xui.Date,sd = date.parse('1/1/2000'),ed = new Date,arr = []; 

  2. arr.push(_.serialize(date.diff(sd,ed,'ms'))); 

  3. arr.push(_.serialize(date.diff(sd,ed,'s'))); 

  4. arr.push(_.serialize(date.diff(sd,ed,'n'))); 

  5. arr.push(_.serialize(date.diff(sd,ed,'h'))); 

  6. arr.push(_.serialize(date.diff(sd,ed,'d'))); 

  7. arr.push(_.serialize(date.diff(sd,ed,'ww'))); 

  8. arr.push(_.serialize(date.diff(sd,ed,'m'))); 

  9. arr.push(_.serialize(date.diff(sd,ed,'q'))); 

  10. arr.push(_.serialize(date.diff(sd,ed,'y'))); 

  11. arr.push(_.serialize(date.diff(sd,ed,'de'))); 

  12. arr.push(_.serialize(date.diff(sd,ed,'c'))); 

  13. alert(arr.join('\n'))

 

^

format ( date,format,firstDayOfWeek )    [函数源代码]

按照给定的格式格式化日期.

返回值: String

参数:

  • date [必需参数] : Date Object, 时间戳.

  • format [必需参数] : String, 时间格式. 可用的时间元素有: (utciso|iso|yyyy|mm|ww|dd|hh|nn|ss|ms|de|c|y|q|m|w|d|h|n|s).

  • firstDayOfWeek [可选参数] : 每周的第一天的编号. 默认为 0.

示例:

- 代码运行js文件 多比手机组态云平台API代码查看器 - 官网

  1. var arr = [],date = xui.Date,d = new Date; 

  2. arr.push(date.format(d,'utciso')); 

  3. arr.push(date.format(d,'iso')); 

  4. arr.push(date.format(d,'ms')); 

  5. arr.push(date.format(d,'s')); 

  6. arr.push(date.format(d,'ss')); 

  7. arr.push(date.format(d,'n')); 

  8. arr.push(date.format(d,'nn')); 

  9. arr.push(date.format(d,'h')); 

  10. arr.push(date.format(d,'hh')); 

  11. arr.push(date.format(d,'d')); 

  12. arr.push(date.format(d,'dd')); 

  13. arr.push(date.format(d,'w')); 

  14. arr.push(date.format(d,'ww')); 

  15. arr.push(date.format(d,'m')); 

  16. arr.push(date.format(d,'mm')); 

  17. arr.push(date.format(d,'q')); 

  18. arr.push(date.format(d,'qa')); 

  19. arr.push(date.format(d,'y')); 

  20. arr.push(date.format(d,'yyyy')); 

  21. arr.push(date.format(d,'de')); 

  22. arr.push(date.format(d,'c')); 

  23. arr.push(date.format(d,'yyyy-mm-dd hh:nn:ss ms')); 

  24. alert(arr.join('\n'))

 

^

get ( date,datepart,firstDayOfWeek )    [函数源代码]

获取时间戳在某个单位上的整数值.

返回值: Number

参数:

  • date [必需参数] : Date Object, 时间戳.

  • datepart [必需参数] : String, 时间单位. 'ms','s','n','h','d','ww','m','q','y','de' or 'c'.

  • firstDayOfWeek [可选参数] : 每周的第一天的编号. 默认为 0.

示例:

- 代码运行js文件 多比手机组态云平台API代码查看器 - 官网

  1. var date = xui.Date,d = new Date(); 

  2. alert('The millisecond of "' + d + '" is: ' + date.get(d,'ms')); 

  3. alert('The second of "' + d + '" is: ' + date.get(d,'s')); 

  4. alert('The minute of "' + d + '" is: ' + date.get(d,'n')); 

  5. alert('The hour of "' + d + '" is: ' + date.get(d,'h')); 

  6. alert('The day of "' + d + '" is: ' + date.get(d,'d')); 

  7. alert('The week of "' + d + '" is: ' + date.get(d,'ww')); 

  8. alert('The week (first day of week is 1)  of "' + d + '" is: ' + date.get(d,'ww',1)); 

  9. alert('The month of "' + d + '" is: ' + date.get(d,'m')); 

  10. alert('The quarter of "' + d + '" is: ' + date.get(d,'q')); 

  11. alert('The year of "' + d + '" is: ' + date.get(d,'y')); 

  12. alert('The decade of "' + d + '" is: ' + date.get(d,'de')); 

  13. alert('The century of "' + d + '" is: ' + date.get(d,'c'));

 

^

getText ( date,datepart,firstDayOfWeek )    [函数源代码]

将时间戳转化为一个可以显示的字符串.

返回值: String

参数:

  • date [必需参数] : Date Object, 时间戳.

  • datepart [必需参数] : String, 显示的时间格式.

  • firstDayOfWeek [可选参数] : 每周的第一天的编号. 默认为 0.

示例:

- 代码运行js文件 多比手机组态云平台API代码查看器 - 官网

  1. var arr = [],date = xui.Date,d = new Date; 

  2. arr.push(date.getText(d,'utciso')); 

  3. arr.push(date.getText(d,'iso')); 

  4. arr.push(date.getText(d,'ms')); 

  5. arr.push(date.getText(d,'s')); 

  6. arr.push(date.getText(d,'n')); 

  7. arr.push(date.getText(d,'h')); 

  8. arr.push(date.getText(d,'d')); 

  9. arr.push(date.getText(d,'w')); 

  10. arr.push(date.getText(d,'ww')); 

  11. arr.push(date.getText(d,'m')); 

  12. arr.push(date.getText(d,'q')); 

  13. arr.push(date.getText(d,'y')); 

  14. arr.push(date.getText(d,'de')); 

  15. arr.push(date.getText(d,'c')); 

  16. arr.push(date.getText(d,'hn')); 

  17. arr.push(date.getText(d,'dhn')); 

  18. arr.push(date.getText(d,'mdhn')); 

  19. arr.push(date.getText(d,'hns')); 

  20. arr.push(date.getText(d,'hnsms')); 

  21. arr.push(date.getText(d,'yq')); 

  22. arr.push(date.getText(d,'ym')); 

  23. arr.push(date.getText(d,'md')); 

  24. arr.push(date.getText(d,'ymd')); 

  25. arr.push(date.getText(d,'ymdh')); 

  26. arr.push(date.getText(d,'ymdhn')); 

  27. arr.push(date.getText(d,'ymdhns')); 

  28. arr.push(date.getText(d,'all')); 

  29. alert(arr.join('\n'))

 

^

getTimSpanEnd ( date,datepart,count,firstDayOfWeek )    [函数源代码]

Gets the 'to' time of the given time span(e.g. 3 hours, 2 day, 1 week...).

返回值: Object, Date Object

参数:

  • date [必需参数] : Date Object, a date to caculate the time span.

  • datepart [必需参数] : String, time span's datepart: 'ms','s','n','h','d','ww','m','q','y','de' or 'c'.

  • count [可选参数] : Number, how many [datepart]s in the time span. 默认为 1.

  • firstDayOfWeek [可选参数] : 每周的第一天的编号. 默认为 0.

示例:

- 代码运行js文件 多比手机组态云平台API代码查看器 - 官网

  1. var date = xui.Date,d = new Date,arr = []; 

  2. arr.push(_.serialize(d)); 

  3. arr.push(_.serialize(date.getTimSpanEnd(d,'ms'))); 

  4. arr.push(_.serialize(date.getTimSpanEnd(d,'s'))); 

  5. arr.push(_.serialize(date.getTimSpanEnd(d,'n'))); 

  6. arr.push(_.serialize(date.getTimSpanEnd(d,'h'))); 

  7. arr.push(_.serialize(date.getTimSpanEnd(d,'d'))); 

  8. arr.push(_.serialize(date.getTimSpanEnd(d,'ww'))); 

  9. arr.push(_.serialize(date.getTimSpanEnd(d,'m'))); 

  10. arr.push(_.serialize(date.getTimSpanEnd(d,'q'))); 

  11. arr.push(_.serialize(date.getTimSpanEnd(d,'y'))); 

  12. arr.push(_.serialize(date.getTimSpanEnd(d,'de'))); 

  13. arr.push(_.serialize(date.getTimSpanEnd(d,'c'))); 

  14. alert(arr.join('\n'))

 

^

getTimSpanStart ( date,datepart,count,firstDayOfWeek )    [函数源代码]

Gets the 'from' time of the given time span(e.g. 3 hours, 2 day, 1 week...).

返回值: Object, Date Object

参数:

  • date [必需参数] : Date Object, a date to caculate the time span.

  • datepart [必需参数] : String, the time span's datepart: 'ms','s','n','h','d','ww','m','q','y','de' or 'c'.

  • count [可选参数] : Number, how many [datepart]s in the time span. 默认为 1.

  • firstDayOfWeek [可选参数] : 每周的第一天的编号. 默认为 0.

示例:

- 代码运行js文件 多比手机组态云平台API代码查看器 - 官网

  1. var date = xui.Date,d = new Date,arr = []; 

  2. arr.push(_.serialize(d)); 

  3. arr.push(_.serialize(date.getTimSpanStart(d,'ms'))); 

  4. arr.push(_.serialize(date.getTimSpanStart(d,'s'))); 

  5. arr.push(_.serialize(date.getTimSpanStart(d,'n'))); 

  6. arr.push(_.serialize(date.getTimSpanStart(d,'h'))); 

  7. arr.push(_.serialize(date.getTimSpanStart(d,'d'))); 

  8. arr.push(_.serialize(date.getTimSpanStart(d,'ww'))); 

  9. arr.push(_.serialize(date.getTimSpanStart(d,'m'))); 

  10. arr.push(_.serialize(date.getTimSpanStart(d,'q'))); 

  11. arr.push(_.serialize(date.getTimSpanStart(d,'y'))); 

  12. arr.push(_.serialize(date.getTimSpanStart(d,'de'))); 

  13. arr.push(_.serialize(date.getTimSpanStart(d,'c'))); 

  14. alert(arr.join('\n'))

 

^

getWeek ( date,firstDayOfWeek )    [函数源代码]

获取时间戳是一年的第几周.

返回值: Number

参数:

  • date [必需参数] : Date Object, 时间戳.

  • firstDayOfWeek [可选参数] : 每周的第一天的编号. 默认为 0.

示例:

- 代码运行js文件 多比手机组态云平台API代码查看器 - 官网

  1. alert(xui.Date.getWeek(new Date))

 

^

offsetTimeZone ( date,targetTimeZone,back )    [函数源代码]

计算时间戳在在指定的time zone上的时间.

返回值: Object, Date Object

参数:

  • date [必需参数] : Date Object, 时间戳.

  • timeZone [必需参数] : integer Number, time zone的编号.

  • back [可选参数] : Boolean, 指示是否使用相反的偏移量. 默认为 [false].

示例:

- 代码运行js文件 多比手机组态云平台API代码查看器 - 官网

  1. var localDate = new Date,timezone9Date = xui.Date.offsetTimeZone(localDate,9); 

  2. alert(localDate.toString() == xui.Date.offsetTimeZone(timezone9Date,9,true))

 

^

parse ( str,format )    [函数源代码]

解析一个字符串,并转化为相应的[Date]对象.

返回值: Object, Date Object

参数:

  • str [必需参数] : String, 表示时间的字符串.

  • foramt [可选参数] : String, 可选的日期时间格式(例如,yyyy-mm-dd 或 dd/mm/yyyy hh:nn:ss ms).

示例:

- 代码运行js文件 多比手机组态云平台API代码查看器 - 官网

  1. alert(xui.Date.parse('1/1/1998'))

 

- 代码运行js文件 多比手机组态云平台API代码查看器 - 官网

  1. alert(xui.Date.parse('Fri Sep 05 2008 11:46:11 GMT+0800'))

 

- 代码运行js文件 多比手机组态云平台API代码查看器 - 官网

  1. alert(xui.Date.parse('2008-09-05T03:46:34.343Z'))

 

- 代码运行js文件 多比手机组态云平台API代码查看器 - 官网

  1. alert(xui.Date.parse('2008-09-05T03:46:34.343+80:00'))


上一篇 下一篇

评论



分享