3

In the joda-time library (and I assume Java 8's new time library), you can ignore times and time zones: https://www.joda.org/joda-time/apidocs/org/joda/time/LocalDate.html

I would prefer to avoid having times factor in in my small app. I just want the user to see their local date. Is there a momentjs equivalent to localdate? If not, would the best workaround be to use .startOf()? Thanks.

Edit: Just to be clear, this is not a formatting question.

JodaStephen
  • 60,927
  • 15
  • 95
  • 117
CarbonandH20
  • 361
  • 1
  • 3
  • 13

1 Answers1

4

"By default, moment parses and displays in local time.

If you want to parse or display a moment in UTC, you can use moment.utc()"

As explained here.

moment().format();     // 2013-02-04T10:35:24-08:00 (local date)
moment.utc().format(); // 2013-02-04T18:35:24+00:00 (UTC date)
Daniel
  • 6,194
  • 7
  • 33
  • 59
  • 1
    Correct me if I'm wrong, but I'm talking about an object that doesn't even have time information. You're talking about formatting. The problem is that the time information is still there and can add issues in terms of calculations even if time isn't displayed. – CarbonandH20 Apr 20 '15 at 21:28
  • Perhaps i misunderstood your question, what do you mean by "an object that doesn't even have time information" and what time calculation issues are you trying to avoid? i thought you just wanted to display the client's localDate, with timezone consideration, and that's done by the moment() function by default – Daniel Apr 20 '15 at 21:51
  • If i understand what you mean, according to http://stackoverflow.com/questions/15130735/how-can-i-remove-time-from-my-date-with-moment-js , it seems that startOf is the best way to have momentjs ignore the time. i'm not sure why would you want to ignore the timezone but you can do it with moment().utc().startOf('day'). – Daniel Apr 21 '15 at 10:58