Skip to content

Commit

Permalink
๐Ÿ“ Docs: dateFormat ์ถ”๊ฐ€
Browse files Browse the repository at this point in the history
  • Loading branch information
wonill committed Dec 4, 2024
1 parent d26f1d8 commit e77f8b2
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/utils/dateFormat.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export const dateToString = (date: Date): string => {
const year = date.getFullYear()
const month = String(date.getMonth() + 1).padStart(2, '0')
const day = String(date.getDate()).padStart(2, '0')

return `${year}-${month}-${day}`
}

export const stringToDate = (dateString: string): Date => {
const [year, month, day] = dateString.split('-').map(Number)
return new Date(year, month - 1, day)
}

0 comments on commit e77f8b2

Please sign in to comment.