# Moment in typescript

**URL:** <https://discourse.aurelia.io/t/moment-in-typescript/1771>\
**Category:** Help Requests\
**Created:** [October 17, 2018, 9:39am UTC](https://discourse.aurelia.io/t/moment-in-typescript/1771 "2018-10-17T09:39:29Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![AndreaProgrammerIt](https://avatars.discourse-cdn.com/v4/letter/a/e9a140/32.png) [@AndreaProgrammerIt](https://discourse.aurelia.io/u/AndreaProgrammerIt)\
**Post date:** [October 17, 2018, 9:39am UTC](https://discourse.aurelia.io/t/moment-in-typescript/1771/1 "2018-10-17T09:39:29Z")

</div>

Hi all,

where could i find a good documentations about “moment” or “date” ??!  
It’s really complex to understand how works this class…

Today is month October( month n° 10) and when i write  
“moment().month()” return 9.  
“moment().months()” return 9;  
“moment().utc).month()” return 9;  
“moment().local().month()” return 9;

but if i write in console “moment” it has the value 10 .

anyone know?!

---

<div class="post-metadata">

**Author:** ![gimerstedt](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.aurelia.io/gimerstedt/32/1103_2.png) [@gimerstedt](https://discourse.aurelia.io/u/gimerstedt)\
**Post date:** [October 17, 2018, 10:58am UTC](https://discourse.aurelia.io/t/moment-in-typescript/1771/2 "2018-10-17T10:58:14Z")

</div>

new Date().getMonth() // 9 (index-0)  
moment().format(‘M’) // 10 (month as digit)

if you are in a position to choose the library, i would recommend against a mutable API like moment.

---

<div class="post-metadata">

**Author:** ![timfish](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.aurelia.io/timfish/32/1566_2.png) [@timfish](https://discourse.aurelia.io/u/timfish)\
**Post date:** [October 17, 2018, 11:08am UTC](https://discourse.aurelia.io/t/moment-in-typescript/1771/3 "2018-10-17T11:08:05Z")

</div>

I recommend [luxon](https://moment.github.io/luxon/):

## Features

- [DateTime](https://moment.github.io/luxon/docs/class/src/datetime.js~DateTime.html), [Duration](https://moment.github.io/luxon/docs/class/src/duration.js~Duration.html), and [Interval](https://moment.github.io/luxon/docs/class/src/interval.js~Interval.html) types.
- Immutable, chainable, unambiguous API.
- Parsing and formatting for common and custom formats.
- Native time zone and Intl support (no locale or tz files).

---

<div class="post-metadata">

**Author:** ![AndreaProgrammerIt](https://avatars.discourse-cdn.com/v4/letter/a/e9a140/32.png) [@AndreaProgrammerIt](https://discourse.aurelia.io/u/AndreaProgrammerIt)\
**Post date:** [October 17, 2018, 12:16pm UTC](https://discourse.aurelia.io/t/moment-in-typescript/1771/4 "2018-10-17T12:16:03Z")

</div>

Thank you to help me.

Meanwhile i tryed to study moment etc and i create this “date-helper”… and seems working…

 ![image](https://canada1.discourse-cdn.com/flex027/uploads/aurelia/original/2X/e/e194d7ccc988fc3ed64f6bff49395fc362b7ccbb.png)

Do you suggest anyway to use luxon ?  
I think that moment functions can be comprehensive… or no?

---

<div class="post-metadata">

**Author:** ![timfish](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.aurelia.io/timfish/32/1566_2.png) [@timfish](https://discourse.aurelia.io/u/timfish)\
**Post date:** [October 17, 2018, 12:23pm UTC](https://discourse.aurelia.io/t/moment-in-typescript/1771/5 "2018-10-17T12:23:45Z")

</div>

Luxon is much smaller and simpler because it relies on newer browser API’s for i18n and timezones. Check out the [support matrix](https://moment.github.io/luxon/docs/manual/matrix.html).

If you need to support i18n and timezones in older browsers you’ll need to use moment + plugins and the whole lot can be quite large.

---

<div class="post-metadata">

**Author:** ![AndreaProgrammerIt](https://avatars.discourse-cdn.com/v4/letter/a/e9a140/32.png) [@AndreaProgrammerIt](https://discourse.aurelia.io/u/AndreaProgrammerIt)\
**Post date:** [October 18, 2018, 9:59am UTC](https://discourse.aurelia.io/t/moment-in-typescript/1771/6 "2018-10-18T09:59:02Z")

</div>

After hours spent on “try” to understand how to work with moment / date of typescript i try this Luxon. It seems workable but how can i get a Luxon DateTime from European Timezone date?

---

<div class="post-metadata">

**Author:** ![AndreaProgrammerIt](https://avatars.discourse-cdn.com/v4/letter/a/e9a140/32.png) [@AndreaProgrammerIt](https://discourse.aurelia.io/u/AndreaProgrammerIt)\
**Post date:** [October 18, 2018, 11:50am UTC](https://discourse.aurelia.io/t/moment-in-typescript/1771/7 "2018-10-18T11:50:30Z")

</div>

With LUXON i’m not able to return to localtime from UTC.

anyone know?

 ![image](https://canada1.discourse-cdn.com/flex027/uploads/aurelia/original/2X/2/2fc9629074878418322d0ff46e97c79a821249e7.png)

---

<div class="post-metadata">

**Author:** ![bhalperin](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.aurelia.io/bhalperin/32/572_2.png) [@bhalperin](https://discourse.aurelia.io/u/bhalperin)\
**Post date:** [October 18, 2018, 11:51am UTC](https://discourse.aurelia.io/t/moment-in-typescript/1771/8 "2018-10-18T11:51:15Z")

</div>

Try e.g. DateTime.local().setZone(‘Europe/Paris’);

---

<div class="post-metadata">

**Author:** ![AndreaProgrammerIt](https://avatars.discourse-cdn.com/v4/letter/a/e9a140/32.png) [@AndreaProgrammerIt](https://discourse.aurelia.io/u/AndreaProgrammerIt)\
**Post date:** [October 18, 2018, 12:05pm UTC](https://discourse.aurelia.io/t/moment-in-typescript/1771/9 "2018-10-18T12:05:59Z")

</div>

![image](https://canada1.discourse-cdn.com/flex027/uploads/aurelia/original/2X/d/ddd6a7b4da7450a2ad45bd4422ccdec25f43563b.png)

Nothing. always utc date

---

<div class="post-metadata">

**Author:** ![AndreaProgrammerIt](https://avatars.discourse-cdn.com/v4/letter/a/e9a140/32.png) [@AndreaProgrammerIt](https://discourse.aurelia.io/u/AndreaProgrammerIt)\
**Post date:** [October 18, 2018, 12:12pm UTC](https://discourse.aurelia.io/t/moment-in-typescript/1771/10 "2018-10-18T12:12:59Z")

</div>

UTCDate.toLocal().plus({ minutes: UTCDate.offset }).toFormat(“dd/MM/yyyy HH:mm”));

this is the answer! but it can be possible to write this entire line to have the local time from utc…

---

<div class="post-metadata">

**Author:** ![brandonseydel](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.aurelia.io/brandonseydel/32/993_2.png) [@brandonseydel](https://discourse.aurelia.io/u/brandonseydel)\
**Post date:** [October 18, 2018, 9:41pm UTC](https://discourse.aurelia.io/t/moment-in-typescript/1771/11 "2018-10-18T21:41:01Z")

</div>

if you have a utc date you can just add Z to the end and it will convert local for you

let localTime = new Date(utcDate + “Z”);
