- 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
廣告