2016-12-10 36 views
0

是否有可能將datepicker中的日期值轉換爲單詞?我知道這裏有幾個類似的問題,但我想要做一個不同的方法。如何將JQuery日期選擇器中的日期值轉換爲單詞

現在我試圖在格式更改爲單詞之前使用alert來查找變量的值,然後存在有關數組中索引號的錯誤消息。它說:uncaught語法錯誤:意想不到的數字是這一行bulan 1 januari

有沒有什麼建議,給數組中的鍵值?

$(function() { 
 
$("#pickyDate").datepicker({format: "dd/mm/yyyy"}); 
 

 
local = ['Minggu', 'Senin', 'Selasa', 'Rabu', 'Kamis', 'Jumat', 'Sabtu' ]; 
 
bulan = [1=>'Januari', 'Februari', 'Maret', 'April', 'Mei', 'Juni','Juli','Agustus','September','Oktober','November','Desember' ]; 
 

 
$('#getdate').datepicker() 
 
.on("change", function() {  
 

 
var today = new Date($('#getdate').datepicker('getDate')); 
 
var tanggal = today.getDate(); 
 
var no_hari = today.getDay(); 
 
var no_bulan = today.getMonth()+1; 
 
var tahun = today.getFullYear(); 
 
    
 
    //alert(local[today.getDay()]); 
 
alert(tahun); 
 
    //$('#wordsdate').val(local[today.getDay()]); 
 

 

 
}); 
 
});
<link href="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.css" rel="stylesheet" /> 
 
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<script src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.js"></script> 
 

 
<div class="form-group"> 
 
    <input type="text" class="form-control" placeholder="choose date" id="getdate" /> 
 
</div> 
 

 
    <div class="form-group"> 
 
    <input type="hidden" class="form-control" placeholder="datepicker date" id="datenum" disabled/> 
 
    </div> 
 

 
    <div class="form-group"> 
 
    <input type="text" class="form-control" placeholder="wordsdate" id="wordsdate" disabled/> 
 
    </div>

例如:
讓說,我們選擇一個日期:2014年5月6日
然後在文本框的結果是:六月兩千第五十四

+0

爲什麼你需要數字作爲單詞?這聽起來不像是一種顯示日期的非常有用的方法。也許「2014年6月5日」會很好,在這種情況下,你可以使用普通的JS。 – gyre

+0

或許首先嚐試https://www.google.com/search?q=convert+date+to+words+javascript – mplungjan

+0

@gyre:這是老闆的要求.. :) – ariowishnu

回答

0

利用資本字母。

你已經寫了DD/MM/YYYY,而不是寫DD/MM/YYYY

+0

只是改變了格式,似乎沒有什麼事情發生隊友 – ariowishnu

+0

嘗試使用date.format庫。 –

+0

那麼如何做到這一點與date.format庫,你可以給一個例如? – ariowishnu

1

您可以使用jQuery的日期選擇器獲得這樣一來,您可以選擇下拉

<!doctype html> 
 
<html lang="en"> 
 
<head> 
 
    <meta charset="utf-8"> 
 
    <meta name="viewport" content="width=device-width, initial-scale=1"> 
 
    <title>jQuery UI Datepicker - Format date</title> 
 
    <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css"> 
 
    <link rel="stylesheet" href="/resources/demos/style.css"> 
 
    <script src="https://code.jquery.com/jquery-1.12.4.js"></script> 
 
    <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script> 
 
    <script> 
 
    $(function() { 
 
    $("#datepicker").datepicker(); 
 
    $("#format").on("change", function() { 
 
     $("#datepicker").datepicker("option", "dateFormat", $(this).val()); 
 
    }); 
 
    }); 
 
    </script> 
 
</head> 
 
<body> 
 
    
 
<p>Date: <input type="text" id="datepicker" size="30"></p> 
 
    
 
<p>Format options:<br> 
 
    <select id="format"> 
 
    <option value="mm/dd/yy">Default - mm/dd/yy</option> 
 
    <option value="yy-mm-dd">ISO 8601 - yy-mm-dd</option> 
 
    <option value="d M, y">Short - d M, y</option> 
 
    <option value="d MM, y">Medium - d MM, y</option> 
 
    <option value="DD, d MM, yy">Full - DD, d MM, yy</option> 
 
    <option value="&apos;day&apos; d &apos;of&apos; MM &apos;in the year&apos; yy">With text - 'day' d 'of' MM 'in the year' yy</option> 
 
    </select> 
 
</p> 
 
    
 
    
 
</body> 
 
</html>
的最後一個選項

+0

需要多一點做st/th/nd – mplungjan

相關問題