Skip to content

Luxon

vue-lux/nuxt is a Vue 3 library that simplifies DateTime formatting and parsing using the powerful Luxon library. Inspired by vue-luxon.

Configuration

You can configure your custom templates or input or output keys by adding the key lux to the we object in your nuxt.config.js file.

Check the guide under template, input, output section to understand more about this topic.

js
we: {
  lux: {
    templates: {
      my_template: {
        format: 'dd__MM__yyyy',
      },
    },
    input: {
      zone: 'utc',
      format: 'iso'
    },
    output: 'short'
  },
}

WARNING

Time zone is set to Europe/Rome by default.

For an advanced configuration take a look at vue-luxon.

Composition Api

js
const date = ref(DateTime.now())

$lux(date, 'short')
// 13/12/2024, 12:00

$lux(date, 'date')
// 13/12/2024

$lux(date, 'time')
// 12:00

import { DateTime } from 'luxon'

const date = ref(DateTime.now())

$lux(date, 'short')
// 13/12/2024 12:00

Legacy

js
const date = new Date().toISOString()

this.$lux(date, 'short')
// 13/12/2024, 12:00

this.$lux(date, 'date')
// 13/12/2024

this.$lux(date, 'time')
// 12:00

// or using luxon

import { DateTime } from 'luxon'

const date = DateTime.now()
this.$lux(date, 'short')
// 13/12/2024 12:00

Formats

NameDescription
short13/12/2024, 10:36
shorts13/12/2024, 10:36:59
date13/12/2024
relative1 giorno fa
iso2024-12-13T10:36:59.826+02:00
med13 dic 2024, 10:36
meds13 dic 2024, 10:36:59
full13 dicembre 2024 alle ore 10:36 CEST
fulls13 dicembre 2024 alle ore 10:36:59 CEST
hugevenerdì 13 dicembre 2024 alle ore 10:36 Ora legale dell’Europa centrale
hugesvenerdì 13 dicembre 2024 alle ore 10:36:59 Ora legale dell’Europa centrale
time10:36
times10:36:59
time24longoffset10:36:59 Ora legale dell’Europa centrale
date_full13 dicembre 2024
date_hugevenerdì 13 dicembre 2024
date_med13 dic 2023
date_meddven 13 dic 2023
date_short6/4/2023
time2409:39
time24s09:39:18
sql2024-12-13 09:39:18.864 +01:00
httpFri, 13 Dec 2024 08:39:18 GMT
jsdateFri Dec 13 2024 09:39:18 GMT+0100 (Ora standard dell’Europa centrale)
rfcFri, 13 Dec 2024 09:39:18 +0100
rfc2822Fri, 13 Dec 2024 09:39:18 +0100
millis1734079158864
unix1734079158.864
seconds1734079158.864
my_template13__12__2024

Tokens

Tokens are useful for formatting and parsing, you can use the following tokens here