skip to Main Content

I’m getting this date time format

Sat Nov 18 2023 22:30:00 GMT+0530 (India Standard Time)

this.selectedDate = info.date;

i want to convert this date time into local date time object but the format will be same

3

Answers


  1. You create a Date object and then call toString().

    let date = new Date("Sat Nov 18 2023 22:30:00 GMT+0530 (India Standard Time)");
    console.log(date.toString());

    Since I’m located in Eastern Europe, it converts the date to my timezone and displays it accordingly:

    enter image description here

    Login or Signup to reply.
  2. const dateStr = "Sat Nov 18 2023 22:30:00 GMT+0530 (India Standard Time)";
    const selectedDate = new Date(dateStr);
    
    const localDateTime = selectedDate.toLocaleString('en-US', {
      timeZone: 'Asia/Kolkata', // Set your desired timezone here
      weekday: 'short',
      month: 'short',
      day: 'numeric',
      year: 'numeric',
      hour: 'numeric',
      minute: 'numeric',
      second: 'numeric'
    });
    
    console.log(localDateTime);
    
    Login or Signup to reply.
  3. Simply you can use the below one line :

    console.log(new Date("Sat Nov 18 2023 22:30:00 GMT+0530 (India Standard Time)").toString());

    Working stackblitz in Angular here.

    enter image description here

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search