
- 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 日期 - toLocaleString()
說明
toLocaleString() 方法使用作業系統本地公約將日期轉換為字串。
toLocaleString 方法依賴於底層作業系統中的日期格式設定。它使用指令碼執行的作業系統的格式化約定將日期轉換為字串。例如,在美國,月份在日期之前 (04/15/98) 顯示,而在德國,日期在月份之前 (15.04.98) 顯示。
語法
下面是 toLocaleString() 方法的語法。
Date.toLocaleString()
返回值
以字串形式返回格式化的日期。
示例
CoffeeScript 中 toLocaleString() 方法用法的示例如下。將此程式碼儲存在名為 date_tolocalestring.coffee 的檔案中。
dt = new Date(1993, 6, 28, 14, 39, 7); console.log dt.toLocaleString()
開啟 命令提示符 並按照如下所示編譯 .coffee 檔案。
c:\> coffee -c date_tolocalestring.coffee
編譯後,會生成以下 JavaScript。
// Generated by CoffeeScript 1.10.0 (function() { var dt; dt = new Date(1993, 6, 28, 14, 39, 7); console.log(dt.toLocaleString()); }).call(this);
現在,再次開啟 命令提示符,並按如下所示執行 CoffeeScript 檔案。
c:\> coffee date_tolocalestring.coffee
執行後,CoffeeScript 檔案會生成以下輸出。
7/28/1993, 2:39:07 PM
coffeescript_date.htm
廣告