day.jsã使ã£ã¦ããã©ããµã¤ãºãå°ãã軽éã¨ã®ãã¨ã§ã
ã¡ãã£ã¨è©¦ãã¦ã¿ãã¨ãã®åå¿é²(*´Ïï½*)
FormKitã®ãã¼ã ãéçºããããã
Tempoã¨ã¯
nativeã®Date
ãæä½ããã¦ã¼ãã£ãªãã£ãªã©ã¤ãã©ãªã
day.jsã¨ã¯éããDate
èªä½ãç´æ¥æä½ããæãã
import { format, parse } from "@formkit/tempo" // Dateã®format const readable = format(new Date(), "full") // Dateã¸ã®parse parse(readable, "full")
ã¿ã¤ã ã¾ã¼ã³ã®ãµãã¼ããæåãã
import { tzDate, format, applyOffset, offset } from "@formkit/tempo" // ã¿ã¤ã ã¾ã¼ã³ãèæ ®ããæ°ããDateãä½æ const newYorkDate = tzDate("2013-11-18 12:00", "America/New_York"); // ã¿ã¤ã ã¾ã¼ã³ãæå®ããformat format({ new Date(), format: "hh:mm a", tz: "America/New_York" }); // ã¿ã¤ã ã¾ã¼ã³ãªãã»ããã®åå¾ const lisbonOffset = offset("2025-03-25 09:30", "Europe/Lisbon") // ãªãã»ããã®é©ç¨ applyOffset("2025-03-25 09:30", lisbonOffset)
æä½é¢æ°ãè±å¯
æ¥ä»ã®è¿½å ã¯ãããªæããsubstructã¯ãªãããã¤ãã¹ãæå®ãã
import { addDay } from "@formkit/tempo" // Add 5 days addDay("2013-03-15", 5)
æ¥ä»ä»¥å¤ã«ãã便å©ãã®ãå¤ãã¦ããããã
- weekStart/weekEnd
- monthStart/monthEnd
- yearStart/yearEnd
ãã ãweekStartãªã©ã¯ãtzDataã渡ãã¦ãã
ã¿ã¤ã ã¾ã¼ã³ã®å½±é¿ãåããã£ã½ãã®ã§æ³¨æãå¿
è¦ããã
import { tzDate, weekStart } from "@formkit/tempo"; const now = tzDate("2024-02-01", "UTC"); console.debug(now.toISOString()); // => 2024-02-01T00:00:00.000Z const weekStartDay = weekStart(now, 1); console.debug(weekStartDay.toISOString()); // => 2024-01-28T15:00:00.000Z const tzStartDay = tzDate(weekStartDay, "Asia/Tokyo"); console.debug(tzStartDay.toISOString()); // => 2024-01-28T15:00:00.000Z
formatã®presetãè±å¯
full/long/midium/shortã®ã¹ã¿ã¤ã«ãç¨æããã¦ãã¦ã
æ¥ä»ã¨æéãããããã§æå®ã§ããã
import { format } from "@formkit/tempo" const date = new Date() format(date, { date: "full", time: "short" }) format(date, { date: "medium", time: "long" }) // localeã®æå®ãOK format(date, "full", "it")
ãã¡ãããèªç±ã«çµã¿ç«ã¦ããã¨ãã§ãããã©ã
millisecondã«ã¯å¯¾å¿ãã¦ãªããããã
import { format } from "@formkit/tempo" const locale = "en" const date = new Date() format(date, "YYYY-MM-DD HH:mm:ss", locale)
Issueã¯ä¸ãã£ã¦ãããããªã®ã§ããã®ãã¡å¯¾å¿ãããããï¼
以ä¸!! ã·ã³ãã«ã§ãããããªã©ã¤ãã©ãª(*´Ïï½*)