0

我有以下代码

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>
  );
}

timevar在本地时区

我想获得timevaras的值,hh:mm:ss这将是一个 UTC 时区转换值

我怎样才能做到这一点。有什么办法可以在组件本身中完成,还是必须在 onSubmit 函数中完成

在屏幕截图中显示我想要的

在此处输入图像描述

密码箱

4

0 回答 0