是否有可能將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日
然後在文本框的結果是:六月兩千第五十四
爲什麼你需要數字作爲單詞?這聽起來不像是一種顯示日期的非常有用的方法。也許「2014年6月5日」會很好,在這種情況下,你可以使用普通的JS。 – gyre
或許首先嚐試https://www.google.com/search?q=convert+date+to+words+javascript – mplungjan
@gyre:這是老闆的要求.. :) – ariowishnu