dev-resources.site
for different kinds of informations.
Day 8: D-8 π±
Published at
12/8/2024
Categories
webdev
beginners
deno
webadvent
Author
valeriavg
Main Article
Author
9 person written this
valeriavg
open
Do you know how many days left till Christmas? Well this little handy library certainly does!
Among other things it allows adding dates, calculating intervals and, of course, formatting dates.
Install it with e.g. deno add npm:date-fns
and use like so:
import { formatDistanceToNow } from "npm:date-fns";
const xMas = new Date("2024-12-25");
console.log(`Christmas is ${formatDistanceToNow(xMas, { addSuffix: true })}`);
Run it with e.g. deno run -A main.ts
and you should get something like this:
deno run -A ./main.ts
Christmas is in 17 days
You can also do things like:
formatDistanceToNow(addDays(new Date(),3), { addSuffix: true }); // in 3 days
formatDistanceToNow(addDays(new Date(),-3), { addSuffix: true }); // 3 days ago
format(new Date(),'yyyy-M-dd'); // 2024-12-08
And a top of that you can also translate it to a localized string:
import { formatRelative, addHours, addDays } from "npm:date-fns";
import { sv, enUS } from "npm:date-fns/locale";
console.log(
formatRelative(addHours(new Date(), 1), new Date(), { locale: sv })
);
console.log(
formatRelative(addDays(new Date(), 1), new Date(), { locale: enUS })
);
Which would get you something like:
deno run -A ./main.ts
# idag kl. 21:09
# tomorrow at 8:09 PM
Liked the content and would love to have more of it all year long?
deno Article's
30 articles in total
Deno docker
read article
Day 24: Paint by Pixels π¨
read article
Day 22: How the Tables have turned π
read article
Day 20: Not a Dedent! π§
read article
Day 23: Terminal Images πΌοΈ
read article
Day 19: Highlight'em up! π
read article
Day 18: Got a millisecond? β±οΈ
read article
You can omit `run` from `deno run` command
read article
Day 17: Terminal Links & Other Escapes π
read article
Day 8: D-8 π±
currently reading
Day 7: Your input is valid ποΈ
read article
π Rust Coders, Donβt Miss These 25 Resource Picks
read article
Day 9: Terminal Forms π
read article
Dynamic DNS sync with Cloudflare
read article
Day 14: Keep on Spinning! β»οΈ
read article
π Automate Your PostgreSQL Backups with Ease! π³
read article
Day 21: In the name of Progress! π
read article
π Automate Your PostgreSQL Backups with Ease! π³
read article
Runtime challenge: Bun vs Node
read article
I built a Fullstack Deno 2 application
read article
Self Writing Lang Graph State
read article
Supabase Just Got More Powerful: Queue, Cron, and Background Tasks in Edge Functions
read article
Day 4: ASCII Art Fonts ποΈ
read article
Day 13: I love Boxes! π¦
read article
#2 Daily Rabbit Holes: Diving Deeper into Rust, V8, and the JavaScriptβ’οΈ Saga
read article
Day 12: Pico-co-colors π₯
read article
π Bun vs Deno: When to Use Each in Your Projects?
read article
Exploring Bun.js Over Deno: A Humble Developer's Tale
read article
Day 10: Ho-ho-hono! π₯
read article
Benchmarking in Node.js vs Deno: A Comprehensive Comparison
read article
Featured ones: