Untitled

 avatar
unknown
plain_text
5 days ago
1.3 kB
3
Indexable
"use client";

import React, { useEffect } from "react";
import moment from "moment-timezone";

function convertStartDateToUTC(dateStr: string, timezone: string) {
  const local = moment.tz(dateStr, timezone).startOf("day");
  const utc = local.utc();
  return utc.format();
}

function convertEndDateToUTC(dateStr: string, timezone: string) {
  const local = moment.tz(dateStr, timezone).endOf("day");
  const utc = local.utc();
  return utc.format();
}

function page() {
  useEffect(() => {
    const selectedStartDate = "2025-04-16";
    const selectedEndDate = "2025-04-17";
    const selectedTimezone = "Asia/Kolkata";

    console.log("---------------- Input ----------------");
    console.log("selectedStartDate", selectedStartDate);
    console.log("selectedEndDate", selectedEndDate);
    console.log("selectedTimezone", selectedTimezone);

    const utcStartDate = convertStartDateToUTC(
      selectedStartDate,
      selectedTimezone
    );
    const utcEndDate = convertEndDateToUTC(selectedEndDate, selectedTimezone);

    console.log("---------------- Output ----------------");
    console.log("utcStartDate", utcStartDate);
    console.log("utcEndDate", utcEndDate);
  }, []);

  return <div>page</div>;
}

export default page;
Editor is loading...
Leave a Comment