|
@@ -21,7 +21,7 @@
|
|
|
<el-icon size="25"><MoreFilled /></el-icon>
|
|
|
<div class="time">
|
|
|
<div>{{time}}</div>
|
|
|
- <span>2025.01.14 星期二</span>
|
|
|
+ <span>{{getCurrentFormattedTime('date')}} {{getCurrentDayOfWeek()}}</span>
|
|
|
</div>
|
|
|
</div>
|
|
|
</div>
|
|
@@ -51,6 +51,30 @@ const toggleFarm = (val) => {
|
|
|
router.push({ name: "Home" });
|
|
|
};
|
|
|
|
|
|
+function getCurrentFormattedTime(type) {
|
|
|
+ const now = new Date();
|
|
|
+
|
|
|
+ const year = now.getFullYear();
|
|
|
+ const month = String(now.getMonth() + 1).padStart(2, '0'); // Months are zero based
|
|
|
+ const day = String(now.getDate()).padStart(2, '0');
|
|
|
+ const hours = String(now.getHours()).padStart(2, '0');
|
|
|
+ const minutes = String(now.getMinutes()).padStart(2, '0');
|
|
|
+ const seconds = String(now.getSeconds()).padStart(2, '0');
|
|
|
+ if(type==='date'){
|
|
|
+ return `${year}.${month}.${day}`;
|
|
|
+ }else{
|
|
|
+ return `${hours}:${minutes}:${seconds}`;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+function getCurrentDayOfWeek() {
|
|
|
+ const now = new Date();
|
|
|
+ const dayOfWeek = now.getDay();
|
|
|
+ const daysOfWeek = ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'];
|
|
|
+
|
|
|
+ return daysOfWeek[dayOfWeek];
|
|
|
+}
|
|
|
+
|
|
|
function formatTimeToHHmmss(date) {
|
|
|
const hours = String(date.getHours()).padStart(2, '0');
|
|
|
const minutes = String(date.getMinutes()).padStart(2, '0');
|
|
@@ -63,7 +87,7 @@ const time = ref("21:05:46")
|
|
|
const timer = ref(null)
|
|
|
onMounted(()=>{
|
|
|
timer.value = setInterval(()=>{
|
|
|
- time.value = formatTimeToHHmmss(new Date())
|
|
|
+ time.value = getCurrentFormattedTime(new Date())
|
|
|
},1000)
|
|
|
})
|
|
|
|