
Kiểu 1: Tháng/ngày/năm (Ví dụ hôm nay là 12/17/2009)
Bạn hãy đặt đoạn code sau tại nơi bạn muốn ngày tháng xuất hiện.
<script language="javascript">
var today_date= new Date()
var month=today_date.getMonth()+1
var today=today_date.getDate()
var year=today_date.getFullYear()
//document.write("Today's date is: ")
document.write(month+"/"+today+"/"+year)
</script>
var today_date= new Date()
var month=today_date.getMonth()+1
var today=today_date.getDate()
var year=today_date.getFullYear()
//document.write("Today's date is: ")
document.write(month+"/"+today+"/"+year)
</script>
Bạn có thể thay đổi font và màu chữ bằng cách kèm theo các lệnh thuộc tính tương thích.
Kiểu 2: Tháng-ngày-năm (Ví dụ hôm nay là 12-17-2009)
Bạn hãy đặt đoạn code sau tại nơi bạn muốn ngày tháng xuất hiện.
<script language="javascript">
var today_date= new Date()
var month=today_date.getMonth()+1
var today=today_date.getDate()
var year=today_date.getFullYear()
//document.write("Today's date is: ")
document.write(month+"-"+today+"-"+year)
</script>
Kiểu 3: Lấy ví dụ hôm nay là ngày 17/12/2009 thì kiểu này hiển thị theo dạng tiếng Anh là December 17, 2009
Đặt đoạn code sau giữa 2 thẻ <head> và </head>.
<script language=javascript>
var today_date= new Date()
var month=today_date.getMonth()
var today=today_date.getDate()
var year=today_date.getFullYear()
var months = new Array(
"January",
"February",
"March",
"April",
"May",
"June",
"July",
"August",
"September",
"October",
"November",
"December");
</script>
Sau đó đặt đoạn code này tại nơi bạn muốn ngày tháng xuất hiện.
<script language=javascript>
document.write(months[month]+" "+today+", "+year)
</script>
Từ những đoạn code Javascript này bạn có thể điều chỉnh để có thể hiển thị ngày tháng theo kiểu tiếng Việt, bạn hãy khám phá nhé!
0 nhận xét