日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

html input日期值,input标签设置时间值

發布時間:2023/12/19 编程问答 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 html input日期值,input标签设置时间值 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

研究了兩天javascript日期相關的內容,一句話總結:“瀏覽器可以用上十萬年,因為javascript支持的時間范圍就是這么長”。

通過實驗來看,比較好用的是type="date",及type="datetime-local"

關于設置值的結論:

(1)2020-03-26格式可用于date、datetime

(2)2020-03-26 22:32:07格式僅可以用于datetime

(3)2020-03-26T22:33:03格式可以用于datetime、datetime-local

關于輸入及校驗日期的正確性:能輸入不代表就能正確轉換成日期

代碼:沒寫過WEB程序,算是個練習,將就著看吧。

table.gridtable {

font-family: verdana,arial,sans-serif;

font-size: 11px;

color: #333333;

border-width: 1px;

border-color: #666666;

border-collapse: collapse;

}

table.gridtable th {

border-width: 1px;

padding: 8px;

border-style: solid;

border-color: #666666;

background-color: #dedede;

text-align: center;

}

table.gridtable td {

border-width: 1px;

padding: 8px;

border-style: solid;

border-color: #666666;

background-color: #ffffff;

}

function FormatDate() {

//var current = new Date();

var now = new Date();

var year = now.getFullYear();

//month返回數組(0-11)

var month = ("0" + (now.getMonth() + 1)).slice(-2);

//getDate返回日期(1-31)

var day = ("0" + now.getDate()).slice(-2);

var formatedDate = year + "-" + month + "-" + day;

//alert("系統時間:" + now + "\n格式化時間:" + formatedDate);

return formatedDate;

}

function FormatDate1() {

//var current = new Date();

var now = new Date();

var year = now.getFullYear();

//month返回數組(0-11)

var month = ("0" + (now.getMonth() + 1)).slice(-2);

//getDate返回日期(1-31)

var day = ("0" + now.getDate()).slice(-2);

var formatedDate = year + "/" + month + "/" + day;

//alert("系統時間:" + now + "\n格式化時間:" + formatedDate);

return formatedDate;

}

function FormatDateTime() {

//var current = new Date();

var now = new Date();

var year = now.getFullYear();

//month返回數組(0-11)

var month = ("0" + (now.getMonth() + 1)).slice(-2);

//getDate返回日期(1-31)

var day = ("0" + now.getDate()).slice(-2);

//

var hour = ("0" + now.getHours()).slice(-2);

var minute = ":" + ("0" + now.getMinutes()).slice(-2);

var second = ":" + ("0" + now.getSeconds()).slice(-2);

var formatedDate = year + "-" + month + "-" + day + " " + hour + minute + second;

//alert("系統時間:" + now + "\n格式化時間:" + formatedDate);

return formatedDate;

}

function FormatDateTimeLocal() {

//var current = new Date();

var now = new Date();

var year = now.getFullYear();

//month返回數組(0-11)

var month = ("0" + (now.getMonth() + 1)).slice(-2);

//getDate返回日期(1-31)

var day = ("0" + now.getDate()).slice(-2);

//

var hour = ("0" + now.getHours()).slice(-2);

var minute = ":" + ("0" + now.getMinutes()).slice(-2);

var second = ":" + ("0" + now.getSeconds()).slice(-2);

var formatedDate = year + "-" + month + "-" + day + "T" + hour + minute + second;

return formatedDate;

}

input標簽typeinput標簽輸入格式測試

input type="date"

input type="datetime"

input type="datetime-local"

function setDate1() {

var str = FormatDate();

$("#lb00001").prop("innerHTML", str);

$('#mydate00001').prop('value',str );

$('#mydate00002').prop('value', str);

$('#mydate00003').prop('value', str)

}

function setDate2() {

var str = FormatDateTime();

$("#lb00002").prop("innerHTML", str);

$('#mydate00001').prop('value', str);

$('#mydate00002').prop('value', str);

$('#mydate00003').prop('value', str);

}

function setDate3() {

var str = FormatDateTimeLocal();

$("#lb00003").prop("innerHTML", str);

$('#mydate00001').prop('value',str);

$('#mydate00002').prop('value', str);

$('#mydate00003').prop('value', str);

}


function dateTest() {

var result="";

$("input[type='date']")

.each(function () {

var v = new Date($(this).val());

result += "\ndate取值:" + $(this).val() + "\n日期時間轉換后的值:" + v

}

);

$("input[type='datetime']")

.each(function () {

var v = new Date($(this).val());

result += "\ndatetime取值:" + $(this).val() + "\n日期時間轉換后的值:" + v

}

);

$("input[type='datetime-local']")

.each(function () {

var v = new Date($(this).val());

result += "\ndatetime-local取值:" + $(this).val() + "\n日期時間轉換后的值:" + v

}

);

alert(result);

};

標簽:slice,設置,month,標簽,prop,str,var,input,now

來源: https://www.cnblogs.com/lnwuyaowei/p/12578090.html

創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎

總結

以上是生活随笔為你收集整理的html input日期值,input标签设置时间值的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。