首页 >> js开发 >> js解决antd datepicker 获取时间默认少8个小时的问题js大全
js解决antd datepicker 获取时间默认少8个小时的问题js大全
发布时间: 2021年1月13日 | 浏览:
| 分类:js开发
1、扩展日期格式化方法
Date.prototype.format = function (fmt) {
let o = {
"M+": this.getMonth() + 1,
//月份
"d+": this.getDate(),
//日
"h+": this.getHours(),
//小时
"m+": this.getMinutes(),
//分
"s+": this.getSeconds(),
//秒
"q+": Math.floor((this.getMonth() + 3) / 3), //季度
"S": this.getMilliseconds()
//毫秒
};
if (/(y+)/.test(fmt)) {
fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
}
for (let 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;
};
Date.prototype.format = function (fmt) {
let o = {
"M+": this.getMonth() + 1,
//月份
"d+": this.getDate(),
//日
"h+": this.getHours(),
//小时
"m+": this.getMinutes(),
//分
"s+": this.getSeconds(),
//秒
"q+": Math.floor((this.getMonth() + 3) / 3), //季度
"S": this.getMilliseconds()
//毫秒
};
if (/(y+)/.test(fmt)) {
fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
}
for (let 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;
};2、对选中日期的时间进行格式化处理,最终得到的时间就是当前时间
new Date(value).format(“yyyy-MM-dd hh:mm:ss”)
new Date(value).format(“yyyy-MM-dd hh:mm:ss”)补充知识:antd datepicker设置开始时间和期限计算出结束时间并且去除周六日补充知识:补充知识:antd datepicker设置开始时间和期限计算出结束时间并且去除周六日datepicker 需要使用moment格式的时间作为value,但是在操作 此value时,包括moment.add()等方法都会直接改变datepicker的值,即使没有重新赋值。此时需要配合moment-immutable-methods使用
import { momentImmutableMethods } from 'moment-immutable-methods'
momentImmutableMethods(moment)
getFinishTime=(value)=>{
const {getFieldValue} = this.props.form
let i = 0
if(typeof(value)==="number"){
let incomingTime = getFieldValue("incomingTime")
while(i
if(incomingTime.addImmu(1,'d').weekday()!==5&&incomingTime.addImmu(1,'d').weekday()!==6){
i++
incomingTime = incomingTime.addImmu(1,'d')
}else{
incomingTime = incomingTime.addImmu(1,'d')
}
}
this.setState({
finishTime:value===16?moment():incomingTime,
disabledFinishTime:value===16?false:true
})
}else if(typeof(value)==="object"){
let deadTime = getFieldValue("deadTime")
while(i
if(value.addImmu(1,'d').weekday()!==5&&value.addImmu(1,'d').weekday()!==6){
i++
value = value.addImmu(1,'d')
}else{
value = value.addImmu(1,'d')
}
}
this.setState({
finishTime:deadTime===16?moment():value,
disabledFinishTime:deadTime===16?false:true
})
}
}
import { momentImmutableMethods } from 'moment-immutable-methods'
momentImmutableMethods(moment)
getFinishTime=(value)=>{
const {getFieldValue} = this.props.form
let i = 0
if(typeof(value)==="number"){
let incomingTime = getFieldValue("incomingTime")
while(i
if(incomingTime.addImmu(1,'d').weekday()!==5&&incomingTime.addImmu(1,'d').weekday()!==6){
i++
incomingTime = incomingTime.addImmu(1,'d')
}else{
incomingTime = incomingTime.addImmu(1,'d')
}
}
this.setState({
finishTime:value===16?moment():incomingTime,
disabledFinishTime:value===16?false:true
})
}else if(typeof(value)==="object"){
let deadTime = getFieldValue("deadTime")
while(i
if(value.addImmu(1,'d').weekday()!==5&&value.addImmu(1,'d').weekday()!==6){
i++
value = value.addImmu(1,'d')
}else{
value = value.addImmu(1,'d')
}
}
this.setState({
finishTime:deadTime===16?moment():value,
disabledFinishTime:deadTime===16?false:true
})
}
}
以上这篇解决antd datepicker 获取时间默认少8个小时的问题就是小编分享给大家的全部内容了,希望能给大家一个参考。
Date.prototype.format = function (fmt) {
let o = {
"M+": this.getMonth() + 1,
//月份
"d+": this.getDate(),
//日
"h+": this.getHours(),
//小时
"m+": this.getMinutes(),
//分
"s+": this.getSeconds(),
//秒
"q+": Math.floor((this.getMonth() + 3) / 3), //季度
"S": this.getMilliseconds()
//毫秒
};
if (/(y+)/.test(fmt)) {
fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
}
for (let 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;
};
Date.prototype.format = function (fmt) {
let o = {
"M+": this.getMonth() + 1,
//月份
"d+": this.getDate(),
//日
"h+": this.getHours(),
//小时
"m+": this.getMinutes(),
//分
"s+": this.getSeconds(),
//秒
"q+": Math.floor((this.getMonth() + 3) / 3), //季度
"S": this.getMilliseconds()
//毫秒
};
if (/(y+)/.test(fmt)) {
fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
}
for (let 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;
};2、对选中日期的时间进行格式化处理,最终得到的时间就是当前时间
new Date(value).format(“yyyy-MM-dd hh:mm:ss”)
new Date(value).format(“yyyy-MM-dd hh:mm:ss”)补充知识:antd datepicker设置开始时间和期限计算出结束时间并且去除周六日补充知识:补充知识:antd datepicker设置开始时间和期限计算出结束时间并且去除周六日datepicker 需要使用moment格式的时间作为value,但是在操作 此value时,包括moment.add()等方法都会直接改变datepicker的值,即使没有重新赋值。此时需要配合moment-immutable-methods使用
import { momentImmutableMethods } from 'moment-immutable-methods'
momentImmutableMethods(moment)
getFinishTime=(value)=>{
const {getFieldValue} = this.props.form
let i = 0
if(typeof(value)==="number"){
let incomingTime = getFieldValue("incomingTime")
while(i
if(incomingTime.addImmu(1,'d').weekday()!==5&&incomingTime.addImmu(1,'d').weekday()!==6){
i++
incomingTime = incomingTime.addImmu(1,'d')
}else{
incomingTime = incomingTime.addImmu(1,'d')
}
}
this.setState({
finishTime:value===16?moment():incomingTime,
disabledFinishTime:value===16?false:true
})
}else if(typeof(value)==="object"){
let deadTime = getFieldValue("deadTime")
while(i
if(value.addImmu(1,'d').weekday()!==5&&value.addImmu(1,'d').weekday()!==6){
i++
value = value.addImmu(1,'d')
}else{
value = value.addImmu(1,'d')
}
}
this.setState({
finishTime:deadTime===16?moment():value,
disabledFinishTime:deadTime===16?false:true
})
}
}
import { momentImmutableMethods } from 'moment-immutable-methods'
momentImmutableMethods(moment)
getFinishTime=(value)=>{
const {getFieldValue} = this.props.form
let i = 0
if(typeof(value)==="number"){
let incomingTime = getFieldValue("incomingTime")
while(i
if(incomingTime.addImmu(1,'d').weekday()!==5&&incomingTime.addImmu(1,'d').weekday()!==6){
i++
incomingTime = incomingTime.addImmu(1,'d')
}else{
incomingTime = incomingTime.addImmu(1,'d')
}
}
this.setState({
finishTime:value===16?moment():incomingTime,
disabledFinishTime:value===16?false:true
})
}else if(typeof(value)==="object"){
let deadTime = getFieldValue("deadTime")
while(i
if(value.addImmu(1,'d').weekday()!==5&&value.addImmu(1,'d').weekday()!==6){
i++
value = value.addImmu(1,'d')
}else{
value = value.addImmu(1,'d')
}
}
this.setState({
finishTime:deadTime===16?moment():value,
disabledFinishTime:deadTime===16?false:true
})
}
}
以上这篇解决antd datepicker 获取时间默认少8个小时的问题就是小编分享给大家的全部内容了,希望能给大家一个参考。