If you have faced problems with calculating dates, you can now convert dates using gloomyDate.js!
If you've ever struggled with converting dates in boards, comments, and so on, you can use gloomyDate.date(str) to convert dates easily.
Developers may find it useful.
function App() {
const [data, setData] = useState([
{ title: 'title1', date: '2022-05-10 10:55:40' },
{ title: 'title2', date: '2023-02-11 15:50:30' }
]);
useEffect(() => {
const newData = [...data];
newData.forEach(e => e.date = gloomyDate.date(e.date, 'en'));
setData(newData);
}, []);
return (
{data.map((elm, idx) =>
{elm.title}
{elm.date}
{/* Expected: 1 years ago */}
)}
);
}
Expected Output
title1
1 years ago
title2
2 months ago
Deployed via npm publish.
npm install gloomydate
This will include gloomyDate in your package.
I made this ES Module to support tree shaking and will also make it available with named exports.
You can use gloomyDate in a common HTML project.
<script src="https://cdn.gloomy-store.com/gloomyDate/gloomyDate.js"></script>
(not using the module system)
The usage is similar to React's.
This supports 3 global languages and accepts 3 types of input.
gloomyDate.date('2023-04-26 08:10:22', 'en') // formatted string
gloomyDate.date('20230426081022', 'jp') // string
gloomyDate.date(1723725494302, 'ko') // number
gloomyDate.date(Number(new Date()) + 1000) // number
Supported languages: 'ko', 'jp', 'en'.
Expected Output:
2 days ago
2日前
2일 전
잠시 후
Default language is Korean ('ko').
Input should be a string or number with a length of 14, or in the format 'YYYY-MM-DD HH:MM:SS'.