Questions tagged [js-joda]

js-joda is an immutable date and time library for javascript.

About

Popular javascript date libraries like moment or date-utils are wrappers around the native javascript Date object, providing syntactic sugar. The native Date object always consist of a date, time and a timezone part. In opposite to that, js-joda is a standalone date and time implementation.

Getting started

Node

Install joda using npm

npm install js-joda

Then require it to any module

var LocalDate = require('js-joda').LocalDate;

var d = LocalDate.parse('2012-12-24').atStartOfDay().plusMonths(2); // 2013-02-24T00:00:00

Browser

To use js-joda from a browser, download either dist/js-joda.min.js or dist/js-joda.js (with sourcemaps for development)

Then add it as a script tag to your page

<script src="js-joda.min.js"></script>
<script>
    var LocalDate = JSJoda.LocalDate;
    var d = LocalDate.parse('2012-12-24').atStartOfDay().plusMonths(2); // 2013-02-24T00:00:00
</script>

Documentation

  • Cheat Sheet Quick start guide
  • API ESDoc generated API documentation
  • js-joda Homepage Project homepage

Links

19 questions
8
votes
0 answers

Formatting js-joda Duration instance

I'd like to display a chrono of elapsed time since the beginning of an operation to a user. I create a Duration instance from a number of seconds, but then, I can't find a way to properly format it like 00:00:23. Do I have to manually get each time…
DSav
  • 903
  • 1
  • 9
  • 11
3
votes
0 answers

How can I get typeorm to work with js-joda

export class ZonedDateTimeTransformer implements ValueTransformer { to(value: ZonedDateTime): Date { return convert(value).toDate(); } from(value: Date): ZonedDateTime { return ZonedDateTime.from(nativeJs(value)); } } @Column({ …
xenoterracide
  • 16,274
  • 24
  • 118
  • 243
3
votes
2 answers

How to compare LocalDate with ZonedDateTime in js-joda?

I'm looking for a way to compare instances of LocalDate and ZonedDateTime in js-joda, but those classes are not compatible. I'm willing to accept, that LocalDate is a ZonedDateTime with time and timezone set to zero. What would be the easiest way to…
Slava Fomin II
  • 26,865
  • 29
  • 124
  • 202
2
votes
1 answer

How do I convert a LocalDateTime to a JavaScript Date object with JS-Joda?

how do I convert a LocalDateTime Object from the @js-joda/core library to a standard JavaScript Date object?
Alex Skotner
  • 462
  • 1
  • 8
  • 18
2
votes
1 answer

How do you parse basic (short/compact) ISO:8601 string with Joda?

I have a time string, which looks like this: 20170822T194135+00. This is called basic ISO:8601 format, if I understood correctly. When I try to parse it using ZonedDateTime, it throws exception, complaining that it can't parse it. SO, how do I…
Slava Fomin II
  • 26,865
  • 29
  • 124
  • 202
2
votes
2 answers

How do you convert any ISO8601 string to LocalTime using js-joda?

I have a full ISO8601 string, which looks like this: 1989-08-16T00:00:00.000Z. How do I create instance of LocalDate from it using js-joda library? When trying to parse it directly with LocalDate.parse(), I'm getting the following…
Slava Fomin II
  • 26,865
  • 29
  • 124
  • 202
1
vote
0 answers

LocalDateTime with minimum LocalDate and Timezone (ZoneId.SYSTEM)

I'm attempting to format a LocalTime object to a formatted string - but due to business requirements I also need to pass a ZoneId to allow for changing the time potentially - then I can format it. What I have currently is something like…
Jack A
  • 11
  • 1
1
vote
2 answers

JavaScript LocaleDateString back to Date Object

INTRODUCTION I have a DatePicker component that returns a JS Native Date Object. When the user selects a date, I automatically convert it to a locale date string, just for making it visible in a text input. Every single text input in my app has a…
Victor Molina
  • 2,353
  • 2
  • 19
  • 49
1
vote
1 answer

Preferred way to serialize/deserialize js-joda LocalDate?

We are using js-joda LocalDate to represent various dates in our model and are storing those dates in sessionStorage. Is there a generalized preferred way of storing those dates so that they can serialize/deserialize without adding special code to…
Bernie B
  • 369
  • 1
  • 2
  • 9
1
vote
2 answers

How to do strict LocalDate parsing in js-joda?

I'm trying to parse a LocalDate from a String using strict resolution in js-joda (version 1.1.1). I don't want to accept inputs that aren't valid dates, like 2016-05-32. But I just don't get it. My code is: formatter = (new…
Tobías
  • 6,142
  • 4
  • 36
  • 62
0
votes
0 answers

Knex.js Data Type Conversion

I'm using zod, knex.js, Tedious, and js-joda with MS SQL Server. I want to pull a few columns as the appropriate js-joda type. For example, start_date is a date and I want it to be deserialized as a LocalDateTime (and vice versa). I'm just not sure…
Chris Pfohl
  • 18,220
  • 9
  • 68
  • 111
0
votes
1 answer

JS-Joda parsing with "YYYY" format

I'm wondering if it's possible at all to parse a string to a LocalDate object including a formatter such as "d/M/YYYY" (specifically including the "YYYY"). It seems a JsJodaException is thrown in the console when attempting to parse this, however…
Jack A
  • 11
  • 1
0
votes
0 answers

How to covert a string in to LocalDate in Js Joda Typescript

Im new to typescript, i have a problem, where i have to convert give string to LocalDate const Date = '31-Oct-2022 2:16:01 PM'; need to convert this string into local date, Tried using LocalDate.Parse(Date), It throws error, tried using…
Lamrin
  • 67
  • 5
0
votes
1 answer

js-joda convert UTC zoned datetime into local datetime

I'm struggling to convert between a parsed UTC datetime into a LocalDateTime (America/New_York), with the hours adjusted accordingly between the two timezones, using the js-joda library. In the javascript native Date object, what's stored is in UTC…
inyourcorner
  • 683
  • 9
  • 26
0
votes
2 answers

Parse the datetime string and convert it to UTC using js-joda/core and js-joda/timezone

We have to build a website for our client that runs Angular 9+ in the front end and nodejs is the server backend application. Everything working good. Now, my client wants to support customers initially from the following timezones: Indian Time,…
Hemant
  • 615
  • 1
  • 8
  • 21
1
2