字串 Number方法 date方法

2021-10-11 21:30:13 字數 1071 閱讀 4095

一、字串

建立字串

var str=「abcde」;//字面量 存在棧中

var str1=new string(「abcde」);//建構函式 存在堆中

字串屬性和方法

str.length//長度  

字串有多少各字元,字串包括字串長度都是不可以直接修改的,唯讀屬性

str.charat()獲取字串下標所對應的字元

str.charcodeat()獲取字串下標所對應的字元unicode編碼

str.concat()拼接字串

indexof lastindexof 和陣列的使用方法完全相同

str.replace()只能替換第乙個被查詢到的

slice

substring不允許使用負數,如果是負數就是0

substr從第幾個位置開始,擷取固定的長度

str.split("|");//使用對應的分隔符將字串轉換為陣列

str.trim();//去掉字串前後空格

number.max_value

number.min_value

number.negative_infinity負無窮

number.positive_infinity正無窮

tostring按進製轉換為字串

tofixed按小數點後幾位轉換

toprecision保留有效數字

toexponential物件的值轉換為指數計數法

new date()

gettime 時間戳 1970.1.1 0時到現在的毫秒數

tolocalestring本地日期時間字串

tolocaledatestring本地日期字串

tolocaletimestring本地時間字串

getfullyear/getyear/getmonth0-11/getdate日期 幾號/

getday星期0-6/gethours/getminutes/getseconds/getmilliseconds

Date物件轉字串

1.tostring 把 date 物件轉換為字串。2.totimestring 把 date 物件的時間部分轉換為字串。3.todatestring 把 date 物件的日期部分轉換為字串。4.togmtstring 請使用 toutcstring 方法代替。5.toutcstring 根據世界時...

字串date型別格式時間串轉化

程式中可能會將date型別直接存在資料庫類似 thu jun 22 19 37 49 cst 2017 型別,此時該字串即不是普通的日期型別轉換的字串型別,也不是日期型別,此時想要轉化為普通的字串日期型別,需要先轉化為普通的日期型別,使用正常的 dateformat 格式不能 進行轉化,需要在平時的...

日期Date和字串之間轉換

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