js 字串和日期物件之間的轉換

2021-08-21 16:48:04 字數 691 閱讀 3848

var strtime=」2011-04-16」; //字串日期格式

var date= new date(date.parse(strtime.replace(/-/g, 「/」))); //轉換成data();

var month=date.getmonth()+1; //獲取當前月份

測試輸出

var d = new date(『2018/7/1』)

console.log(d)

var str = 『2010-08-01』

str = str.replace(/-/g, 『/』)

var date = new date(str)

console.log(date)

var date = this.ruleform.date //獲取form表單裡面的日期

var date_str = date.tolocaledatestring() //轉成本地的日期時間格式

var date_list = date_str.split(『/』) //拆分

console.log(date_list[0]) //列印出獲得的日期字串

var time = this.ruleform.time //獲取form表單裡面的時間

var time_str = time.totimestring() //轉換成本地的時間格式

Json字串和js物件之間的轉換

var str1 var str2 以 localstorage 為例,sessionstorage 用法一樣 setitem 儲存資料 localstorage.setitem key,value 示例 localstorage.setitem name hello world 當 key 相同時...

日期Date和字串之間轉換

date string 格式化 public final string format date date string date 解析 public date parse string source dateforamt 可以進行日期和字串的格式化和解析,但是由於是抽象類,所以使用具體子類 date...

JS中陣列 物件 字串之間的轉換

1 陣列轉字串 var a 1 2,3 4,5 var b a.tostring var c string a console.log b 1,2,3,4,5 console.log typeof b string console.log c 1,2,3,4,5 console.log typeof...