-
常用的js,字符截取,时间转换
-
-
-
-
-
-
- function getSubString(str,length){
- var subStr ="";
- if(str.length > length){
- subStr = str.substring(0,length)+"...";
- }else{
- subStr= str;
- }
- return subStr;
- }
-
-
-
-
-
-
- function subStr(s,l,d){
- if(s == undefined){
- return "";
- }
- s=s.replaceAll(" ","|");
- l=l*2;
- var r = /[^\x00-\xff]/g;
- if(s.replace(r, "zz").length <= l){
- return s.replaceAll("\\|"," ");
- }
- var m = Math.floor(l/2);
- for(var i=m; i<s.length; i++){
- if(s.substring(0, i).replace(r, "zz").length>=l) {
- var str=s.substring(0, i).replaceAll("\\|"," ");
- if(d==undefined){
- return str+"...";
- }else{
- return str;
- }
- }
- }
- return s.replaceAll("\\|"," ");
- }
-
-
-
-
-
-
-
- jQuery.removeHtml = function(s){
- return (s)? jQuery("<p>").append(s).text(): "";
- }
-
-
-
-
-
- jQuery.escapeHtml=function(s){
- return (s)? jQuery("<p>").text(s).html(): "";
- }
-
-
-
-
-
- function contentSubmitBefore(s){
- return (s)?s.replaceAll("\r\n","<br>").replaceAll("\n","<br>").replaceAll("\r","<br>"):"";
- }
-
-
-
-
-
- function contentSubmitAfter(s){
- return (s)?s.replaceAll("<","<").replaceAll(">",">").replaceAll("<br>","<br/>").replaceAll("<br/>","<br/>"):"";
- }
-
-
-
-
-
- function htmlTagReplace(s){
- return (s)?s.replaceAll("<","<").replaceAll(">",">"):"";
- }
-
-
-
-
-
-
- function getDate(timestamp,type){
- var timeCreated = new Date(timestamp);
- if(type == undefined){
-
- var timeFormated = timeCreated.getFullYear() +"-" + (timeCreated.getMonth()+1) +"-"+timeCreated.getDate() +" " +timeCreated.getHours()+":" + timeCreated.getMinutes() ;
- return timeFormated;
- }if(type == 1){
-
- var timeFormated = timeCreated.getFullYear() +"-" + (timeCreated.getMonth()+1) +"-"
- +timeCreated.getDate() +" " +timeCreated.getHours()+":" + timeCreated.getMinutes() ;
- }else if(type == 2){
-
- var timeFormated = timeCreated.getFullYear() +"-" +(timeCreated.getMonth()+1) +"-"
- +timeCreated.getDate() +" " +timeCreated.getHours()+":" + timeCreated.getMinutes()
- +":"+timeCreated.getSeconds();
- }else if( type == 3){
-
- var timeFormated = timeCreated.getFullYear() +"-" + (timeCreated.getMonth()+1) +"-"
- +timeCreated.getDate();
- }
- return timeFormated;
- }
-
-
-
-
-
- function getDateDiff(d,now){
- if(now==undefined){
- now=new Date().getTime();
- }else{
- now=Date.parse(now.replace(/-/g,'/').replace(/:/g,":"));
- }
- var diffValue = now - Date.parse(d.replace(/-/g,'/').replace(/:/g,":"));
- if(diffValue < 0){
- return "刚刚";
- }
- var minute = 1000 * 60;
- var hour = minute * 60;
- var day = hour * 24;
- var halfamonth = day * 15;
- var month = day * 30;
- var monthC =diffValue/month;
- var weekC =diffValue/(7*day);
- var dayC =diffValue/day;
- var hourC =diffValue/hour;
- var minC =diffValue/minute;
- if(monthC>=1){
- result=parseInt(monthC) + "个月前";
- }else if(weekC>=1){
- result=parseInt(weekC) + "个星期前";
- }else if(dayC>=1){
- result= parseInt(dayC) +"天前";
- }else if(hourC>=1){
- result= parseInt(hourC) +"个小时前";
- }else if(minC>=1){
- result= parseInt(minC) +"分钟前";
- }else{
- result="刚刚";
- }
- return result;
- }
-
-
-
-
-
-
-
-
- function getSmpFormatDate(date,isFull){
- var pattern = "";
- if (isFull==true||isFull==undefined) {
- pattern = "yyyy-MM-dd hh:mm:ss";
- } else {
- pattern = "yyyy-MM-dd";
- }
- return getFormatDate(date,pattern);
- }
-
-
-
-
-
-
-
-
- function getSmpFormatNowDate(isFull){
- return getSmpFormatDate(new Date(),isFull);
- }
-
-
-
-
-
-
-
-
- function getSmpFormatDateByLong(l,isFull){
- return getSmpFormatDate(new Date(l),isFull);
- }
-
-
-
-
-
-
- function getFormatDateByLong(l,pattern){
- return getFormatDate(new Date(l),pattern);
- }
-
-
-
-
-
-
- function getFormatDate(date,pattern){
- if(date==undefined){
- date=new Date();
- }
- if(pattern==undefined){
- pattern="yyyy-MM-dd hh:mm:ss";
- }
- return date.format(pattern);
- }
-
-
-
-
-
-
-
-
-
-
-
- jQuery.fn.woyoObserver=function(max,fun,type){
- $(this).delayedObserver(function(){
- var _this=$(this);
- if(type==1){
- var _r = /[^\x00-\xff]/g;
- var _s=$.trim(_this.val());
- var _m=_s.replace(_r, "zz").length;
- fun(max-Math.floor(_m/2),_this.val(),this);
- }else{
- fun(max-$.trim(_this.val()).length,_this.val(),this);
- }
- },0.0001);
- }
-
-
-
-
-
- function getDayOfWeek(date){
- var today = new Array("周日","周一","周二","周三","周四","周五","周六");
- return today[new Date(date).getDay()];
- }
-
-
-
-
-
-
- function formatStartEndDate(start,end){
- if(end<start){return "时间错误";}
- var c=end-start;
- var minute = 1000 * 60;
- var hour = minute * 60;
- var day = hour * 24;
- if(parseInt(c/day)<=0){
- var d=new Date(start).format("MM月dd日");
- var week=getDayOfWeek(start);
- var t1=new Date(start).format("hh:mm");
- var t2=new Date(end).format("hh:mm");
- return d+" "+week;
- }else{
- var d1=new Date(start).format("MM月dd日");
- var d2=new Date(end).format("MM月dd日");
- var w1=getDayOfWeek(start);
- var w2=getDayOfWeek(end);
- var t1=new Date(start).format("hh:mm");
- var t2=new Date(end).format("hh:mm");
- return d1+" "+w1+" - "+d2+" "+w2;
- }
- }
- 补struts中的标签显示时间的
- <s:property value="gmtCreatedString.substring(0,16)"/>,从哪里开始显示
-
相关阅读:
《人月神话》阅读笔记3
团队冲刺0110
团队冲刺0109
团队冲刺0108
团队冲刺0107
团队冲刺0106
团队冲刺0105
团队冲刺010304
团队冲刺0102
团队冲刺0101
-
原文地址:https://www.cnblogs.com/canphp/p/2397713.html
Copyright © 2020-2023
润新知