[Vuejs]-Why does vue-datepicker add 4 hours to the time selected by the user

0👍

It works this way because it reads the UTC time by default. For example, when I was trying it now, I was getting 6am since my timezone is +3. To get actual time from your date, you can convert it to locale:

<template>
  <VueDatePicker v-model="date" />
</template>

<script setup>
import VueDatePicker from "@vuepic/vue-datepicker";
import "@vuepic/vue-datepicker/dist/main.css";
import { ref } from "vue";

const date = ref<Date | null>();

function getLocaleTime() {
  if (!date.value) return;

  return date.value.toLocaleDateString();
}
</script>

Leave a comment