Skip to content

Commit

Permalink
Merge pull request #123 from prgrms-web-devcourse-final-project/122-f…
Browse files Browse the repository at this point in the history
…eature/add-dateFormat

[Feature] dateFormat 추가
  • Loading branch information
wonill authored Dec 4, 2024
2 parents d26f1d8 + e77f8b2 commit 905381a
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 905381a

Please sign in to comment.