Boolean和Date类型的扩展

本文为翻译,英文原版的Cheat Sheet(PDF版本)在此下载:http://aspnetresources.com/downloads/ms_ajax_library_cheat_sheets1.zip

 

注:标注有[S]的为静态方法,无须实例化对象即可使用。

 

[S] Boolean.parse (value )

从字符串表示的布尔值解析成相应的Boolean类型。value参数必须为“true”或“false”二者之一,不区分大小写,且可以包含空格。

var b = Boolean.parse("true");

 

Date.format (format)

格式化字符串(区域设定无关)。

var d = new Date();
Sys.Debug.trace (d.format("dddd, dd MMMM yyyy HH:mm:ss"));

 

Date.localeFormat (format)

格式化字符串(区域设定相关)。使用Sys.CultureInfo.CurrentCulture得到区域属性。

var d = new Date();
Sys.Debug.trace (d.localeFormat("dddd, dd MMMM yyyy HH:mm:ss"));

 

[S] Date.parseLocale (value, formats)

从字符串表示的本地时间日期解析成相应的Date类型。使用Sys.CultureInfo.CurrentCulture得到区域属性。

Sys.Debug.trace (Date.parseLocale ("4/10/2001", "yyyy-MM-dd",
"MM/dd/yyyy"));
// Date.parseLocale will skip the first format here as invalid and use
// the second one. If it does not find an appropriate format,
// the function throws an exception.

 

[S] Date.parseInvariant (value, formats)

从字符串表示的区域无关时间日期解析成相应的Date类型。

Sys.Debug.trace (Date.parseInvariant ("4/10/2001", "yyyy-MM-dd",
"MM/dd/yyyy"));
// Date.parseInvariant will skip the first format here as invalid and use
// the second one. If it does not find an appropriate format,
// the function throws an exception.

 

支持的格式

 

  1. d: 缩写日期(e.g.: 02/17/2007):
  2. D: 完整日期(e.g: Saturday, 17 February 2007)
  3. t: 缩写时间(e.g.: 22:10)
  4. T: 完整时间(e.g.: 22:10:30)
  5. F: 完整时间日期(e.g.: Saturday, 17 February 2007 22:10:30)
  6. m (or M): 月和日(e.g.: February 17)
  7. s: 可排序的时间日期(e.g.: 2007-02-17T22:10:30)
  8. y (or Y): 年和月(e.g.: 2007 February)

相关文章

随机推荐:

相关链接

helloajax.com
专注Ajax、Asp.Net、JavaScript技术