- CoffeeScript 教程
- CoffeeScript - 首页
- CoffeeScript - 概述
- CoffeeScript - 环境
- CoffeeScript - 命令行工具
- CoffeeScript - 语法
- CoffeeScript - 数据类型
- CoffeeScript - 变量
- CoffeeScript - 运算符和别名
- CoffeeScript - 条件语句
- CoffeeScript - 循环
- CoffeeScript - 列表推导式
- CoffeeScript - 函数
- CoffeeScript 面向对象编程
- CoffeeScript - 字符串
- CoffeeScript - 数组
- CoffeeScript - 对象
- CoffeeScript - 范围
- CoffeeScript - 展开运算符
- CoffeeScript - 日期
- CoffeeScript - 数学
- CoffeeScript - 异常处理
- CoffeeScript - 正则表达式
- CoffeeScript - 类和继承
- CoffeeScript 高级
- CoffeeScript - Ajax
- CoffeeScript - jQuery
- CoffeeScript - MongoDB
- CoffeeScript - SQLite
- CoffeeScript 有用资源
- CoffeeScript - 快速指南
- CoffeeScript - 有用资源
- CoffeeScript - 讨论
CoffeeScript 日期 - toLocaleTimeString()
描述
toLocaleTimeString() 方法将日期转换为字符串,使用当前区域设置的约定返回“日期”部分。
toLocaleTimeString 方法依赖于底层操作系统来格式化日期。它使用运行脚本的操作系统的格式化约定将日期转换为字符串。例如,在美国,月份出现在日期之前 (04/15/98),而在德国,日期出现在月份之前 (15.04.98)。
语法
以下是toLocaleTimeString() 方法的语法。
Date.toLocaleTimeString()
返回值
返回格式化后的日期字符串。
示例
以下示例演示了在 CoffeeScript 中toLocaleTimeString() 方法的用法。将此代码保存到名为date_tolocaletimestring.coffee 的文件中。
dt = new Date(1993, 6, 28, 14, 39, 7); console.log dt.toLocaleTimeString()
打开命令提示符并编译 .coffee 文件,如下所示。
c:\> coffee -c date_tolocaletimestring.coffee
编译后,它会生成以下 JavaScript 代码。
// Generated by CoffeeScript 1.10.0
(function() {
var dt;
dt = new Date(1993, 6, 28, 14, 39, 7);
console.log(dt.toLocaleTimeString());
}).call(this);
现在,再次打开命令提示符,并运行 CoffeeScript 文件,如下所示。
c:\> coffee date_tolocaletimestring.coffee
执行后,CoffeeScript 文件会产生以下输出。
2:39:07 PM
coffeescript_date.htm
广告