date-fns#getHours JavaScript Examples
The following examples show how to use
date-fns#getHours.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: index.js From bank-client with MIT License | 5 votes |
export default function Greeting() {
const { user, dateFormat } = useSelector(stateSelector);
return (
<StyledGreeting>
<div>
{getHours(new Date()) > 20 ? (
<FormattedMessage {...messages.goodEvening} />
) : (
<FormattedMessage {...messages.goodMorning} />
)}
,{' '}
<StyledNameWrapper>
{user?.firstName} {user?.lastName}
</StyledNameWrapper>
</div>
{user?.userAuth?.lastSuccessfulLoggedDate && (
<div>
<FormattedMessage {...messages.lastSuccessfulLogin} />{' '}
<StyledLastSuccessfulLoggedDateWrapper>
{format(
new Date(user?.userAuth?.lastSuccessfulLoggedDate),
dateFormat,
)}
</StyledLastSuccessfulLoggedDateWrapper>
</div>
)}
{user?.userAuth?.lastFailedLoggedDate && (
<div>
<FormattedMessage {...messages.lastFailedLogin} />{' '}
<StyledLastFailedLoggedDate>
{format(new Date(user?.userAuth?.lastFailedLoggedDate), dateFormat)}
</StyledLastFailedLoggedDate>
</div>
)}
</StyledGreeting>
);
}
Example #2
Source File: dateFns.js From the-eye-knows-the-garbage with MIT License | 4 votes |
generateConfig = {
// get
getNow: function getNow() {
return new Date();
},
getWeekDay: function getWeekDay(date) {
return getDay(date);
},
getYear: function getYear(date) {
return _getYear(date);
},
getMonth: function getMonth(date) {
return _getMonth(date);
},
getDate: function getDate(date) {
return _getDate(date);
},
getHour: function getHour(date) {
return getHours(date);
},
getMinute: function getMinute(date) {
return getMinutes(date);
},
getSecond: function getSecond(date) {
return getSeconds(date);
},
// set
addYear: function addYear(date, diff) {
return addYears(date, diff);
},
addMonth: function addMonth(date, diff) {
return addMonths(date, diff);
},
addDate: function addDate(date, diff) {
return addDays(date, diff);
},
setYear: function setYear(date, year) {
return _setYear(date, year);
},
setMonth: function setMonth(date, month) {
return _setMonth(date, month);
},
setDate: function setDate(date, num) {
return _setDate(date, num);
},
setHour: function setHour(date, hour) {
return setHours(date, hour);
},
setMinute: function setMinute(date, minute) {
return setMinutes(date, minute);
},
setSecond: function setSecond(date, second) {
return setSeconds(date, second);
},
// Compare
isAfter: function isAfter(date1, date2) {
return _isAfter(date1, date2);
},
isValidate: function isValidate(date) {
return isValid(date);
},
locale: {
getWeekFirstDay: function getWeekFirstDay(locale) {
var clone = Locale[dealLocal(locale)];
return clone.options.weekStartsOn;
},
getWeek: function getWeek(locale, date) {
return _getWeek(date, {
locale: Locale[dealLocal(locale)]
});
},
format: function format(locale, date, _format) {
if (!isValid(date)) {
return null;
}
return formatDate(date, _format, {
locale: Locale[dealLocal(locale)]
});
},
parse: function parse(locale, text, formats) {
for (var i = 0; i < formats.length; i += 1) {
var format = formats[i];
var formatText = text;
var date = parseDate(formatText, format, new Date(), {
locale: Locale[dealLocal(locale)]
});
if (isValid(date)) {
return date;
}
}
return null;
}
}
}