1

I'm trying to set up the current time of a process but I just want to set up the day not the time/seconds like Tue, 28 Sep 2021.

I know 2 ways of doing dates and that would be:

new Date().toTimezoneString() and firebase.firestore.FieldValue.serverTimestamp() both of them includes time though.

and I know that if I set up Date() alone it store the data as a date format instead of a string.

Extra: can it be set up in other languages as well ?

ReactPotato
  • 1,262
  • 3
  • 26
  • 46
  • It's not clear what you are asking for in your question. Are you after a `string` type? If so, in what format? Are you looking for numerical data for each date component (year, month, day of month)? Should the date be in the local time zone or in UTC? etc. – jsejcksn Sep 28 '21 at 06:25

1 Answers1

1

Use Intl ( Internationalization API ) to format your dates. It's supported by all browsers and provides a comprehensive api to suit your date and time formatting needs.

Here is the doc for the method you need: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/DateTimeFormat

For your use-case where you dont want to show time, you simply do not pass timeStype in the options parameter to the Intl formatter. Example would be

const date = new Date();
const formattedDate = new Intl.DateTimeFormat('en-US', { dateStyle: 'medium' }).format(date) 
alchemist95
  • 759
  • 2
  • 9
  • 26