前端向后端传递一个 Date 类型的参数,你可以通过获取这个 Date 的年、月、日、时、分、秒来判断它是否包含年月日或者时分秒。
具体来说,你可以使用 JavaScript 中 Date 对象的一些方法来获取这些信息,例如 getFullYear()、getMonth()、getDate()、getHours()、getMinutes() 和 getSeconds()。
例如,你可以这样判断一个 Date 是否包含年月日:
if (date.getFullYear() && date.getMonth() && date.getDate()) {
// 该 Date 包含年月日
}
同理,你也可以判断它是否包含时分秒:
if (date.getHours()&& date.getMinutes() && date.getSeconds()) {
// 该 Date 包含时分秒
}