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

I suggest you to add more information about how you are going to use that
timevar, because it may dramatically ease your task.If
timevarshould be processed anyhow after the form is submitted, for example sent via network request, then the easiest way is to convert it to UTC and then to string by doing:If you want to use string representation in render, then you could use
useMemoto calculate the string on each date change, like:And finally, if you don't care much about performance, and you feel pretty confident with moment's UTC functions you may transform all inputs and outputs on the input component, like this: