Every line of 'date format in react js' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.
139 function getDate(dateObj) { 140 var date; 141 if (typeof dateObj.diff === 'function') { 142 date = dateObj.toDate(); 143 } else { 144 date = new Date(dateObj.year, dateObj.month - 1, dateObj.day); 145 } 146 return new Moment(date).unix() * 1000; 147 }
23 function useDateValues(props: BasePickerProps, options: StateHookOptions) { 24 const utils = useUtils(); 25 const date = useValueToDate(utils, props); 26 const format = props.format || options.getDefaultFormat(); 27 28 return { date, format }; 29 }
117 export function useFormatDate(date: Date): string { 118 return format(date, getState().format); 119 }
3 export default function formatDate (date) { 4 return format(date, 'MM-dd'); 5 }
16 export function actualDate(date) { 17 return new Date(flatpickr.parseDate(date, DATE_FORMAT)); 18 }
182 getDateInstance( v ) { 183 return this.props.moment( v ).toDate(); 184 }
159 static getDerivedStateFromProps(nextProps, prevState) { 160 const { selectedDate, value } = nextProps; 161 let nextDateValue = selectedDate; 162 163 // Use the value for a controlled component if one is provided. 164 if (value !== undefined && value !== null) { 165 nextDateValue = value; 166 } 167 168 if (nextDateValue !== prevState.prevPropsSelectedDate) { 169 const nextSelectedDate = DateUtil.createSafeDate(nextDateValue); 170 171 if (nextSelectedDate) { 172 return { 173 selectedDate: nextSelectedDate, 174 prevPropsSelectedDate: nextDateValue, 175 }; 176 } 177 178 return { 179 prevPropsSelectedDate: nextDateValue, 180 }; 181 } 182 183 return null; 184 }
14 function DynamicDateInput(props) { 15 const { 16 additionalLabel, 17 focus, 18 id, 19 jsDateFormat, 20 label, 21 locale, 22 required, 23 } = props; 24 25 const { data, setData, ui } = React.useContext(DynamicLayoutContext); 26 const value = Object.getByString(data, id); 27 28 return React.useMemo(() => { 29 const handleDayChange = day => setData({ 30 [id]: day ? timezone(day) 31 .format('YYYY-MM-DD') : null, 32 }); 33 34 return ( 35 36 <span>{label}</span> 37 38 39 40 41 42 ); 43 }, [props, value, setData]); 44 }
150 function getDateString(date) { 151 return format(date, 'yyyy-MM-dd'); 152 }
41 export function checkDateValue(props, propName, componentName) { 42 // 支持传入 moment 对象或字符串,字符串不检测是否为日期字符串 43 if ( 44 props[propName] && 45 !moment.isMoment(props[propName]) && 46 typeof props[propName] !== 'string' 47 ) { 48 return new Error( 49 `Invalid prop ${propName} supplied to ${componentName}. Required a moment object or format date string!` 50 ); 51 } 52 }