Skip to content

Commit

Permalink
convert timezone locally (#24)
Browse files Browse the repository at this point in the history
* fix time zone bug
  • Loading branch information
Hy0tic authored Apr 9, 2024
1 parent 4ef922b commit baaf752
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
7 changes: 6 additions & 1 deletion components/Chat.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
{{ chat.username }}
</span>
<span class="time text-[0.8rem] text-sm text-[#777]">{{
chat.time
convertToLocaleTime(chat.time)
}}</span>
</div>
<p class="text m-0 text-white">{{ chat.text }}</p>
Expand All @@ -32,6 +32,7 @@

<script setup lang="ts">
import { watch, nextTick } from "vue"
import moment from "moment"
interface Chat {
username: string
Expand All @@ -49,6 +50,10 @@ const scrollToBottom = () => {
})
}
const convertToLocaleTime = (utcTime: string) => {
return moment.utc(utcTime).local().format("h:mm a")
}
const props = defineProps<{
chats: Chat[]
}>()
Expand Down
2 changes: 1 addition & 1 deletion server/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ export function formatMessage(username: string, text: string) {
return {
username,
text,
time: moment().format("h:mm a"),
time: moment().utc().format("YYYY-MM-DDTHH:mm:ss"),
}
}

Expand Down

0 comments on commit baaf752

Please sign in to comment.