First, Date Object
Definition: Date () can return the day and time of the system; Note: The time format of the callout is returned Sun 07 22:50:03 2016
Usage:
Date()
1.1 Getting the Time object
var date = Date();
1.2 Convert to Time object
new Date(2015, 5, 10); new Date("2015-5-10") new Date(1465869212484);
1.3 Date.parse Converts a date-formatted string into milliseconds, and returns Nan if the date is not formatted correctly
//获得的是一个字符串类型的毫秒形式时间Date.parse("2015-5-10")//获得的是一个字符串类型的毫秒形式时间+new Date()////获得的是一个字符串类型的毫秒形式时间var date = new Date();date.valueOf();date.getTime()
1.4 Common methods for date objects
GetTime ()Returns the number of milliseconds for the entire event as well as the valueof () result getmilliseconds ()The number of milliseconds that the event was returned Getseconds ()Returns the seconds in the time returned 0-59 getminutes ()Returns the Minutes in the event 0-59 getHours ()Return the little things in Time 0-23 GetDay ()Return days 0 Sunday 6 weeks 6 getDate ()Returns the day ordinal of the current month GetMonth ()Return month, starting from 0 getfullyear ()Returns a 4-bit year such as 2016VarDate=NewDate ();2015-12-12 13:14:12Year Console.LogDate. getFullYear ());Month-Starting from 0 console.LogDate. GetMonth ()+1);Day of the current month 1 ~ + Console.LogDate. GetDate ());Get the week, Sunday is 0 console.log (date. GetDay ()); //hour console. Log (date. getHours ()); //min console. Log (date. getminutes ()); //Sec console. Log (date. getseconds ()); //MS console. Log (date. getmilliseconds ());
Second, string Operation 2.1 charAt ()
- Definition: Returns the character at the specified position
- Usage: charAt (index), index is the subscript of the string, the first character in the string if not added by default, as required argument
var str = "abcoefoxyozzopp";console.log(str.charAt());//str为储存字符串的变量,为h5提供的方法str[index]
2.2 substr (Star,length)
- Definition: Extracting a fixed-length string from a string
- Usage: substr (star,length) The first argument represents the starting string subscript, the second parameter represents the length of the string to extract
Parameters |
Description |
Index |
Must be a numeric value that represents the beginning of the first item in the string. If a negative number indicates that the search starts after the string, 1 represents the last character |
Length |
Optional, which represents the length of the string to extract, and if omitted does not write the entire string is truncated |
- Note: The return is a new string , this is not a standard ECMAScript standard, so it is not recommended to use
2.3 IndexOf ()
- Definition: You can return the first position of a character in a specified string.
- Usage: indexOf (searchstring,position) The first argument represents the character that needs to be looked up, and the second parameter represents the beginning of the search
var str = "abceofoxyozzopp"; console.log(str.indexOf(‘o‘,4));
Parameters |
Description |
Index |
The required argument that represents the character to find. |
Position |
Optional, starting with the first of several strings, the legal range is 0~str.length-1. If this argument is omitted, it is retrieved from the first character of the string. |
- Note: If not found, return-1
2.3 Replace (regexp,replacement)
- Definition: Replacing a string in a string that matches the first filter condition with the second argument
- Usage: replace (regexp,replacement), the first parameter represents the filter condition, the second parameter represents the string to replace, (can be a function).
var str = "abce of oxy oz zopp"; console.log(str.replace(//g,‘‘)); var str = "abce of oxy oz zopp"; var newStr = str.replace(/ /g, function () { return ‘*‘; }) console.log(newStr);
Note: The return is a completely new string, the original string does not change
At night nothing to do, tidy up the string and array of commonly used methods, share to everyone.