format_hippo.js
来自「Hippo CMS是一个以信息为中心的开源内容管理系统。Hippo CMS目标是」· JavaScript 代码 · 共 46 行
JS
46 行
/*
* Copyright 2008 Hippo (www.onehippo.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
Date.padded2 = function(hour) { padded2 = hour.toString(); if ((parseInt(hour) < 10) || (parseInt(hour) == null)) padded2="0" + padded2; return padded2; }
Date.prototype.getAMPMHour = function() { hour=Date.padded2(this.getHours()); return (hour == null) ? 00 : (hour > 24 ? hour - 24 : hour ) }
Date.prototype.getAMPM = function() { return (this.getHours() < 12) ? "" : ""; }
Date.prototype.getPaddedHours = function() { return Date.padded2(this.getHours()); }
Date.prototype.getPaddedDate = function() { return Date.padded2(this.getDate()); }
Date.prototype.getPaddedMonth = function() { return Date.padded2(this.getMonth() + 1); }
Date.prototype.toFormattedString = function(include_time){
str = this.getPaddedDate() + "-" + this.getPaddedMonth() + "-" + this.getFullYear();
if (include_time) { str += " " + this.getPaddedHours() + ":" + this.getPaddedMinutes() +":00" }
return str;
}
Date.parseFormattedString = function (string) {
var regexp = '([0-9]{1,2})\-(([0-9]{1,2})\-(([0-9]{4})( ([0-9]{1,2}):([0-9]{2})? *)?)?)?';
var d = string.match(new RegExp(regexp, "i"));
if (d==null) return Date.parse(string); // at least give javascript a crack at it.
var offset = 0;
var date = new Date(d[5], 0, 1);
if (d[3]) { date.setMonth(d[3] - 1); }
if (d[5]) { date.setDate(d[1]); }
if (d[7]) {
date.setHours(parseInt(d[7], 10));
}
if (d[8]) { date.setMinutes(d[8]); }
if (d[10]) { date.setSeconds(d[10]); }
return date;
}
// Make Monday the first day of the week:
Date.weekdays = $w("M T W T F S S");
Date.first_day_of_week = 1;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?