0

I want to parse date and time from the following time stamp in my Nuxt3 project using Date Fns. on Date select on calender, this is the value we get.

const SelectedDate = "Sat Jul 02 2022 14:56:04 GMT+0530 (India Standard Time)"

I want to extract date and time from this, like.

Const Date = "02/07/2022"
Const Time = "14:56"

but i get wrong time, as result i get -

const Time = "14:07"

I have used this.

<script setup>
import { ref, reactive } from "vue";
import { format, compareAsc } from 'date-fns'
let pickdate = ref(new Date());

const FormattedDate = ref(format(pickdate.value, 'dd/MM/yyyy'))
const FormattedTime = ref(format(pickdate.value, 'HH:MM'))
</script>
kissu
  • 40,416
  • 14
  • 65
  • 133
  • The format of the timestamp is consistent with that produced by [*Date.prototype.toString*](https://262.ecma-international.org/#sec-date.prototype.tostring), so can be reliably parsed by the built–in parser, then [formatted however you wish](https://stackoverflow.com/questions/3552461/how-do-i-format-a-date-in-javascript). – RobG Jul 02 '22 at 09:47
  • What is wrong here? The `Date` one? – kissu Jul 02 '22 at 10:47

0 Answers0