我的日期是mm / yyyy格式。我需要将此日期与今天的日期进行比较。我已经转换了今天的日期。
转换后,我得到的日期格式为mm / dd / yyyy ..但是我需要将其转换为mm / yyyy格式..以便我可以将此日期与要获取的日期进行比较。任何帮助请
selecteddate=05/2019 //which is in mm/yyyy format
myDate= new Date().toLocaleDateString(); //which is in mm/dd/yyyy format( I need to convert this date into mm/yyyy format and need to compare with selecteddate)
答案 0 :(得分:2)
let date = new Date().toLocaleDateString('en-US', {year: 'numeric', month: '2-digit' })
console.log(date)
答案 1 :(得分:2)
您可以如下使用Moment.js:
moment().format('MM/YYYY')
答案 2 :(得分:1)
希望这会有所帮助,
if(orderType!=null && user_id!=null) {
// Call method 1
}else if(user_id!=null) {
// Call method 2
}else if(orderType!=null) {
// Call method 3
}
答案 3 :(得分:0)
import datetime
selecteddate='05/2019'
selecteddate= datetime.datetime.strptime(selecteddate, '%m/%Y')
today_dtime= datetime.datetime.now()
today_dtime.date()>selecteddate.date()
输出:真 向下记下月份和年份的一件事将指定为选定的日期,但日期将为受尊敬的月份的1号。 试试这个简单的把戏
答案 4 :(得分:0)
您可以使用以下逻辑将您选择的日期与今天的日期进行比较
const selectedDate="05/2019"; // MM/YYYY
const today = new Date();
const todayString = `${(today.getMonth() + 1)}/${today.getFullYear()}`;
const matched = ( todayString === todayString );
console.log("Does your selected date matched with today's date ?",(matched ? "Matched":"Don't Matched"));