DEV Community

Discussion on: FullStack - How to create a working blogging website with pure HTML, CSS and JS in 2021.

Collapse
 
ats1999 profile image
Rahul kumar

Why are you doing date.getDate() + date.getTime() + file.name;

github.com/kunaal438/blogging-site...

Collapse
 
themodernweb profile image
Modern Web

Well, I am doing this to give a unique name to uploaded image for example if, user uploads an image "img.png" then the uploaded image on server side will have current date and time to make that image specific. Than the uploaded image maybe look like this. "1657381749img.png"

Collapse
 
ats1999 profile image
Rahul kumar • Edited

getTime() would be sufficient to give unique id, date.getDate() is unnecessary.

Because for any instance of time, both will be same.

Thread Thread
 
themodernweb profile image
Modern Web

I think getDate can give more uniqueness. And if we want to see specific date published images we can also filter it.

Thread Thread
 
ats1999 profile image
Rahul kumar • Edited

getTime() is same as getDate(), getTime() will return unix epoch time in milli seconds.

You can also see date from getTime ().

Advantage of getTime()":

  • sort by date because getTime () is just a number

  • sort by date range

  • smaller image name

  • etc...

Thread Thread
 
themodernweb profile image
Modern Web

Oh! My bad😅😅, I didn't knew about it. Thanks for telling 😄😄

Some comments have been hidden by the post's author - find out more