// Obtain the string length to distinguish between Chinese and English characters. prototype. getbytes = function () {var Carr = This. match (/[^ \ x00-\ xFF]/ig); return this. length + (CARR = NULL? 0: Carr. length);} // specifies the length of the truncated string. in the excess part, specify a string instead of the string to be referenced. prototype. getbytes string. prototype. cutbytes = function (strlen, replacestr) {var STR = This. tostring (); If (Str. getbytes () <= strlen) return STR; var returnstr = ""; var templen = 0; For (VAR I = 0; I <Str. length; I ++) {var tempchar = STR [I]. match (/[^ \ x00-\ xFF]/ig); returnstr + = STR [I]; templen + = tempchar = NULL? 1: 2; If (templen> = strlen) {return I + 1 <Str. length? Returnstr + replacestr: returnstr ;}} return "";};
/**
* Extended Date: converts date to a string in the specified format.
* Month (M), Day (D), 12 hours (H), 24 hours (H), minute (M), second (s), Week (E), quarter (q) can use 1-2 placeholders
* Year (y) can use 1-4 placeholders, Millisecond (s) can only use 1 placeholder (1-3 digits)
* Eg:
* (New date (). pattern ("yyyy-mm-dd hh: mm: Ss. s") => 08:09:04. 423
* (New date (). pattern ("yyyy-mm-dd e hh: mm: SS") => 20:09:04
* (New date (). pattern ("yyyy-mm-dd EE hh: mm: SS") => 08:09:04 Tuesday
* (New date (). pattern ("yyyy-mm-dd EEE hh: mm: SS") => 08:09:04 Tuesday
* (New date (). pattern ("yyyy-m-d h: M: S. S") => 2006-7-2. 18
*/Date. prototype. pattern = function (FMT) {var o = {"m +": This. getmonth () + 1, // month "d +": This. getdate (), // Day "H +": This. gethours () % 12 = 0? 12: This. gethours () % 12, // Hour "H +": This. gethours (), // Hour "m +": This. getminutes (), // minute "s +": This. getseconds (), // second "q +": math. floor (this. getmonth () + 3)/3), // quarter "S": This. getmilliseconds () // millisecond}; var week = {"0": "\ u65e5", "1": "\ u4e00", "2": "\ u4e8c ", "3": "\ u4e09", "4": "\ u56db", "5": "\ u4e94", "6": "\ u516d "}; if (/(Y + )/. test (FMT) {FMt = FMT. replace (Regexp. $1, (this. getfullyear () + ""). Substr (4-Regexp. $1. length);} If (/(E + )/. test (FMT) {FMt = FMT. replace (Regexp. $1, (Regexp. $1. length> 1 )? (Regexp. $1. length> 2? "\ U661f \ u671f": "\ u5468"): "") + week [this. getday () + ""]);} For (var k in O) {If (New Regexp ("(" + K + ")"). test (FMT) {FMt = FMT. replace (Regexp. $1, (Regexp. $1. length = 1 )? (O [k]): ("00" + O [k]). substr ("" + O [k]). length) ;}} return FMT ;};