Replies: 1 comment
-
updated code but still not working :
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi. I'm using date-fns-tz. But I can't change the timezone in my component. It will always convert to +0 UTC. I have tried everything but none of them worked. Can someone please help me?
DateTimePicker component
`import { formatInTimeZone } from 'date-fns-tz';
import { vi } from "date-fns/locale";
import { Calendar as CalendarIcon } from "lucide-react";
import { cn } from "@/lib/utils";
import { Button } from "@/components/ui/button";
import { Calendar } from "@/components/ui/calendar";
import {
Popover,
PopoverContent,
PopoverTrigger,
} from "@/components/ui/popover";
import { TimePicker } from "./time-picker";
interface DateTimePickerProps {
date: Date | undefined;
setDate: (date: Date | undefined) => void;
}
export function DateTimePicker({ date, setDate }: DateTimePickerProps) {
const timeZone = 'Asia/Ho_Chi_Minh';
const handleSelect = (newDay: Date | undefined) => {
if (!newDay) return;
const newDate = new Date(newDay);
if (date) {
newDate.setHours(date.getHours(), date.getMinutes(), date.getSeconds());
console.log(newDate);
} else {
const now = new Date();
newDate.setHours(now.getHours(), now.getMinutes(), now.getSeconds());
console.log(newDate);
}
setDate(newDate);
};
return (
<Button
variant={"outline"}
className={cn(
"w-auto justify-start text-left font-normal",
!date && "text-muted-foreground"
)}
>
{date ? (
formatInTimeZone(date, timeZone, 'PPP HH:mm:ss', { locale: vi })
) : (
Chọn thời gian
)}
);
}
`
Beta Was this translation helpful? Give feedback.
All reactions