-
Notifications
You must be signed in to change notification settings - Fork 5
/
app.vue
97 lines (71 loc) · 2.13 KB
/
app.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<template>
<div>
<select v-model="currentLocale">
<option
v-for="locale in locales"
:key="locale.value"
:value="locale.value"
>
{{ locale.name }} {{ locale.value }}
</option>
</select>
<h1>Example: Date formatting</h1>
<p>Unformatted: {{ new Date() }}</p>
<p>
Formatted with dayjs (template):
{{ $dayjs(new Date()).format("DD/MM/YYYY") }}
</p>
<p>Formatted with dayjs (computed): {{ prettyDate }}</p>
<p>
Formatted with dayjs (RelativeTime): {{ $dayjs(new Date()).fromNow() }}
</p>
<p>
Formatted locale : {{ $dayjs(new Date()).format('L') }}
</p>
<ul>
<li v-for="month in $dayjs.months()">
{{ month }}
</li>
</ul>
<p>UTC: {{ $dayjs.utc().format() }}</p>
<p>Weekday: {{ $dayjs().weekday() }}</p>
<p>Day of year: {{ $dayjs().dayOfYear() }}</p>
<p>Duration: {{ $dayjs.duration(10000) }}</p>
{{ $dayjs(new Date()).isBetween('2023-01-01', '2023-02-01', 'day', '[)') }}
<p>Is Leap year? {{ $dayjs().isLeapYear() }}</p>
<p>Is same or after 2023-04-30 ? {{ $dayjs().isSameOrAfter('2023-04-30', 'day') }}</p>
<p>Is same or before 2023-04-30 ? {{ $dayjs().isSameOrBefore('2023-04-30', 'day') }}</p>
<p>Start of day to Now: {{ $dayjs($dayjs().startOf('day')).toNow() }}</p>
<div> Timezone :</div>
<select v-model="currentTimezone">
<option
v-for="item in timezones"
:value="item"
>
{{ item }}
</option>
</select>
<div>
{{ $dayjs().tz(currentTimezone).format('DD/MM/YYYY HH:mm z') }}
</div>
</div>
</template>
<script setup>
const locales = ref([
{ name: 'English', value: 'en' },
{ name: 'Spanish', value: 'es' },
{ name: 'Portuguese', value: 'pt' },
]);
const currentLocale = ref('en');
const currentTimezone = ref('America/New_York');
const timezones = ref(['America/New_York',
'Asia/Taipei',
]);
const { $dayjs } = useNuxtApp();
const prettyDate = computed(() =>
$dayjs(new Date()).format('dddd, MMMM D, YYYY h:mm A'),
);
watch(currentLocale, newVal => {
$dayjs.locale(newVal);
});
</script>