Enkode
Enkode

Reputation: 4783

Angular Date Functions

I am new to Angular and am having trouble doing simple date functions.

$scope.publishDate = new Date().setHours(0);

This works but these do not

$scope.publishDate = new Date().setMinutes(0);
$scope.publishDate = new Date().addDays(0);

Do I need add additional libraries like angular-moment or geomoment to have these extra date functions?

Upvotes: 0

Views: 2414

Answers (3)

jcamelis
jcamelis

Reputation: 1309

I recently created a wrapper for use moment inside angular,

https://github.com/jcamelis/angular-moment

You can use all moment methods as angular filters.

Upvotes: 1

JakeSidSmith
JakeSidSmith

Reputation: 933

Dates can be awkward in Javascript, especially if you're new to them.

I've been using moment on an angular project recently and would totally recommend it, though you don't need it.

It makes getting, setting and formatting dates incredibly easy. :)

Upvotes: 0

Dalorzo
Dalorzo

Reputation: 20014

Those are native functions and depends on each browser to implement the ECMA Script standard that applies. The good news is that those features should be present in all browser these days.

Here is a link if you want to learn more about the standard and the version and browsers that supports it:

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setHours

Upvotes: 0

Related Questions