-4

l am try to get timestamp format like this way 201909081015 with out using any hash or dash ! .

any idea to how to do this format ?

Ali Ghassan
  • 1,280
  • 1
  • 22
  • 59
  • @EliasSoares no is not . l am try to get time format like that 201909081015 without any hash !!!!!! – Ali Ghassan Sep 08 '19 at 20:07
  • 2
    Read the answers, show some effort. – Elias Soares Sep 08 '19 at 20:08
  • i read it but is not what l am looking for – Ali Ghassan Sep 08 '19 at 20:08
  • @AliGhassan the answers explain how to format a date in general, whatever your desired format it. You're supposed to read them, then find the appropriate pattern to use in order to obtain your specific format, based on what the answer explains, and on the documentation of the methods involved. Sure it doesn't say: copy and paste this code. – JB Nizet Sep 08 '19 at 20:10
  • Almost all answers explain how to extract the day, month, year from a date. Do you know how to concatenate strings? Do it. The same logic apply for the time itself. Just google: Javascript Date Methods – Elias Soares Sep 08 '19 at 20:11

2 Answers2

2

If UTC timezone will do,

new Date().toISOString().replace(/\D/g, '').substr(0, 12)

It would take more work to handle other timezone offsets.

This works by simply taking the typical toISOString() format, then throwing away everything that isn't a digit, and trimming off anything beyond the minutes digits.

kshetline
  • 12,547
  • 4
  • 37
  • 73
  • Thank you he is working now . but i have question . can i forward minutes like 1815 . 1830 , 1845 . it is possible ?? – Ali Ghassan Sep 08 '19 at 20:16
  • If you wanted to round up (or round off) the minutes, that'll take more work, because then you've got to get into dealing with individual time zone fields. Rounding down (so 0-14 -> 0, 15-29 -> 15, etc.) is easier. – kshetline Sep 08 '19 at 20:19
  • l want to round up minutes because this time timestamp format is for satellite image weather . and all images are working only with this format . so l have to forward minutes 15 for even l get satellite image – Ali Ghassan Sep 08 '19 at 20:21
  • 1
    This expression will round a date upwards to the nearest 15 minutes: `new Date(Math.ceil(originalDate.getTime() / 900000) * 900000)` – kshetline Sep 08 '19 at 23:29
0

if you dont' want to use hash or dash, you can use different methods of Date() object like getFullYear, getMonth... etc. Live Example: Stackblitz

Md Rafee
  • 5,070
  • 3
  • 23
  • 32