• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (C) 2024 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 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
16module.exports = {
17    getDateTime,
18    getRunTime
19}
20
21function getDateTime() {
22    const date = new Date();
23    let year = date.getFullYear().toString();
24    let month = ("0" + (date.getMonth() + 1)).slice(-2);
25    let day = ("0" + date.getDate()).slice(-2);
26    let hour = ("0" + date.getHours()).slice(-2);
27    let minute = ("0" + date.getMinutes()).slice(-2);
28    let second = ("0" + date.getSeconds()).slice(-2);
29    let millSecond = ("0" + date.getMilliseconds()).slice(-3);
30    return year + month + day + hour + minute + second + millSecond;
31}
32function getRunTime(startTime) {
33    let endTime = new Date().getTime();
34    let duration = endTime - startTime;
35    let hours = Math.floor(duration / (1000 * 60 * 60));
36    let minutes = Math.floor((duration % (1000 * 60 * 60)) / (1000 * 60));
37    let seconds = Math.floor((duration % (1000 * 60)) / 1000);
38    let formattedTime = `${hours}小时${minutes}分钟${seconds}秒`;
39    return formattedTime;
40}
41