Я пытался получить currentDate в пользовательском интерфейсе, который мне удалось получить, и по щелчку даты мы получаем текущую дату, но по умолчанию отображается
дд / мм / гггг вместо показа точной даты.
Я хочу, чтобы дата отображалась вместо дд / мм / гггг.
Вот модифицированный код в материале пользовательского интерфейса, а вот ссылка на коды и коробки
песочница
import React from 'react';
import PropTypes from 'prop-types';
import { withStyles } from '@material-ui/core/styles';
import TextField from '@material-ui/core/TextField';
const styles = theme => ({
container: {
display: 'flex',
flexWrap: 'wrap',
},
textField: {
marginLeft: theme.spacing.unit,
marginRight: theme.spacing.unit,
width: 200,
},
});
var today = new Date();
var dd = today.getDate();
var mm = today.getMonth() + 1; //January is 0!
var yyyy = today.getFullYear();
if (dd < 10) {
dd = '0' + dd
}
if (mm < 10) {
mm = '0' + mm
}
today = mm + '/' + dd + '/' + yyyy;
//document.write(today);
function DatePickers(props) {
const { classes } = props;
return (
<form className={classes.container} noValidate>
<TextField
id="date"
type="date"
defaultValue={today}
className={classes.textField}
InputLabelProps={{
shrink: true,
}}
/>
</form>
);
}
DatePickers.propTypes = {
classes: PropTypes.object.isRequired,
};
export default withStyles(styles)(DatePickers);