1/* 2 * Copyright (c) 2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16// 时间格式 调整 17export default class FormDate { 18 // 月+日 19 formMonthDay(goal?: string) { 20 let date = goal ? new Date(goal) : new Date() 21 return `${this.fill(date.getMonth() + 1)}/${date.getDate()}` 22 } 23 24 // 换算当前星期几 25 formDay() { 26 let day = new Date().getDay() 27 if (day === 1) { 28 return '星期一' 29 } else if (day === 2) { 30 return '星期二' 31 } else if (day === 3) { 32 return '星期三' 33 } else if (day === 4) { 34 return '星期四' 35 } else if (day === 5) { 36 return '星期五' 37 } else if (day === 6) { 38 return '星期六' 39 } else if (day === 7) { 40 return '星期日' 41 } 42 } 43 44 // 格式化 当前分钟 45 fill(num?: number) { 46 return num > 9 ? '' : '0' + num 47 } 48 49 // 当前时间节点称谓 50 formTimeSlot(hour?: number) { 51 let now = hour ? hour : new Date().getHours() 52 if (now >= 0 && now <= 8) { 53 return '早上' 54 } else if (now >= 9 && now < 11) { 55 return '上午' 56 } else if (now >= 11 && now <= 13) { 57 return '中午' 58 } else if (now >= 14 && now <= 16) { 59 return '下午' 60 } else if (now >= 17 && now <= 19) { 61 return '傍晚' 62 } else if (now >= 19 && now <= 23) { 63 return '晚上' 64 } 65 } 66}