I have the following code
import "./styles.css";
import {
Col,
Row,
Form,
InputGroup,
Container
} from "reactstrap";
import React from "react";
import { useForm, Controller } from "react-hook-form";
import "react-datetime/css/react-datetime.css";
import Datetime from "react-datetime";
export default function App() {
const onSubmit = (data) => {
console.log(data);
};
const { control, handleSubmit, watch } = useForm({
defaualtValues: {
timevar: new Date(new Date().setHours(0, 0, 0, 0))
}
});
console.log(watch("timevar"));
return (
<Container>
<Form onSubmit={handleSubmit(onSubmit)}>
<Row className="m-3">
<Col>
<InputGroup className="mb-3">
<Controller
name="timevar"
control={control}
render={({ field }) => (
<Datetime
{...field}
timeFormat={"h:mm A Z"}
dateFormat={false}
value={field.value}
/>
)}
/>
</InputGroup>
</Col>
</Row>
</Form>
</Container>
);
}
The timevar
will be in localtime zone
I want to get the value of timevar
as hh:mm:ss
and this will be a UTC time zone converted value
How can i do this. Is there any way i can do it in the component itself or do i have to get this done in the onSubmit function
Showing what I want in screenshot