21
kurtr
7y

I want to stab the person that decided to make dates in JavaScript so fucking complicated to format.

Comments
  • 1
    I use moment.js and having no issue making it work with a .net service in terms of formatting date for .net to understand. Though I'm not JS expert just a noob finding his way lol
  • 2
    @gitpush Yeah I've used moment and a few others. What pisses me off is time like now when I just need to display some thing like the current date once and don't want to import a whole library so I end up writing a 15 line function for it. Getting a date like 1st July 2017 is fucking insanely difficult. I wish js had php's date style i.e. date('Y-m-d')
  • 0
    @kurtr aah I see your point, yes this is just fked up. I guess JS is not dev friendly :S
  • 2
    Watch the video about internationalizing code or timezone madness by computerphile and you will probably understand...
  • 0
    @stimulate Very good video. Js dates still suck though
  • 1
    It's really not that hard:

    let d = new Date();
    let monthLookup = ['January', 'February'.....]
    let formatted = `${d.getDay()}st ${monthLookup[d.getMonth()]}, ${d.getFullYear()}`;

    Verbose - yes.
    Hard - not really.

    ¯\_(ツ)_/¯

    P.s @gitpush: use date-fns over moment. Moment is hilariously big (hundreds of kb minified).
  • 0
    @yusijs thanks for the hint 😀
  • 1
    @gitpush np! I usually start off with moment (habits etc), but noticed with the stats-output from webpack that it adds a tremendous amount of redundant code. If you use a shitton of it then that's fine, but normally I use maybe 3-4 functions. Adding such a huge library seems silly when there are alternatives :)
  • 0
    @yusijs that will make dates like 6st July 2017. It doesn't handle nth's
  • 0
    @yusijs yup but coming from .Net with our spoiled datetime class moment looks easiest for now, though gotta learn alternatives 😀
  • 1
    @kurtr true, but wouldnt be to hard to implement. Not to many checks:
    1st, 21st, 31st
    2nd, 22nd
    3rd, 23rd
    4th-20th, 24th-30th

    May have missed a case here and there but eh.

    Again - verbose, yes. Not hard though.
  • 1
    @gitpush yeah I know, I love the simplicity in Go as well. Formatting dates is a breeze.
  • 0
    @yusijs everything not JS related seems to be easy :P
  • 2
    @gitpush mate that's a rule of life. Javascript is amazing. It's like riding a bike. Except the bike is on fire and you're on fire and everything is on fire and you're in hell.
  • 0
    @yusijs lol liked your example XD
  • 1
    @gitpush thanks, I stole it from google myself!
Add Comment