Date Fns How Do I Format To Utc

date-fns | How do I format to UTC

Tags: javascript , datetime , date , date-fns Answers: 1 | Viewed 52,703 times



Problem


It looks like when I use the format() function, it automatically convert the original UTC time into my timezone (UTC+8). I have been digging through their docs for hours and couldn't seem to find a way to default it to UTC time.


import { parseISO, format } from "date-fns";
const time = "2019-10-25T08:10:00Z";
const parsedTime = parseISO(time);
console.log(parsedTime); // 2019-10-25T08:10:00.000Z
const formattedTime = format(parsedTime, "yyyy-MM-dd kk:mm:ss");
console.log(formattedTime); // 2019-10-25 16:10:00 <-- 8 HOURS OFF!!

I have tried to use the package data-fns-tz and use something like


format(parsedTime, "yyyy-MM-dd kk:mm:ss", {timeZone: "UTC"});

still no luck.


Please help!


Expected Output


2019-10-25 08:10:00


Actual Output


2019-10-25 16:10:00


Some Answers For Date Fns How Do I Format To Utc

#1. Date fns how do i format to utc | Autoscripts.net


import { parseISO, format } from "date-fns";
const time = "2019-10-25T08:10:00Z";
const parsedTime = parseISO(time);
console.log(parsedTime);
// 2019-10-25T08:10:00.000Z const formattedTime = format(parsedTime, "yyyy-MM-dd kk:mm:ss");
console.log(formattedTime);
// 2019-10-25 16:10:00 <-- 8 HOURS OFF!!

format(parsedTime, "yyyy-MM-dd kk:mm:ss", {timeZone: "UTC"});

import { parseISO } from "date-fns";
import { format, utcToZonedTime } from "date-fns-tz";
const time = "2019-10-25T08:10:00Z";
const parsedTime = parseISO(time);
console.log(parsedTime);
// 2019-10-25T08:10:00.000Z const formatInTimeZone = (date, fmt, tz) =>
format(utcToZonedTime(date, tz),

fmt,

{ timeZone: tz });
const formattedTime = formatInTimeZone(parsedTime, "yyyy-MM-dd kk:mm:ss xxx", "UTC");
console.log(formattedTime);
// 2019-10-25 08:10:00 +00:00

import { format, addMinutes } from 'date-fns';
function formatDate(date) {
return format(addMinutes(date, date.getTimezoneOffset()), 'yyyy-MM-dd HH:mm:ss');
}

const date = new Date("2019-10-25T08:10:00Z");
const isoDate = date.toISOString();
console.log(`${isoDate.substr(0, 10)} ${isoDate.substr(11, 8)}`);

import format from 'date-fns/format';
import parseISO from 'date-fns/parseISO';
export const adjustForUTCOffset = date =>
{
return new Date(
date.getUTCFullYear(),
date.getUTCMonth(),
date.getUTCDate(),
date.getUTCHours(),
date.getUTCMinutes(),
date.getUTCSeconds(),
);
};
const formatDate = (dateString) = >
{
const date = parseISO(dateString);
const dateWithOffset = adjustForUTCOffset(date)
return format(dateWithOffset, 'LLL dd, yyyy HH:mm') }

const now = new Date()
const date = format(
new Date(now.toISOString().slice(0, -1)),
'yyyy-MM-dd HH:mm:ss'
)

import { parseISO, format } from "date-fns";
const time = "2019-10-25T08:10:00Z";
const parsedTime = parseISO(new Date(Date.UTC(time)));
const formattedTime = format(parsedTime, "yyyy-MM-dd kk:mm:ss");

const formatDate = new Date().toISOString().substr(0, 19).replace('T', ' ');

import { format, addMinutes } from 'date-fns';
function formatDate(date) {
return format(addMinutes(date, date.getTimezoneOffset()), 'yyyy-MM-dd HH:mm:ss');
}

import { parseISO } from "date-fns";
import { format, utcToZonedTime } from "date-fns-tz";
const time = "2019-10-25T08:10:00Z";
const parsedTime = parseISO(time);
console.log(parsedTime);
// 2019-10-25T08:10:00.000Z const formatInTimeZone = (date, fmt, tz) =>
format(utcToZonedTime(date, tz),

fmt,

{ timeZone: tz });
const formattedTime = formatInTimeZone(parsedTime, "yyyy-MM-dd kk:mm:ss xxx", "UTC");
console.log(formattedTime);
// 2019-10-25 08:10:00 +00:00

const date = new Date("2019-10-25T08:10:00Z");
const isoDate = date.toISOString();
console.log(`${isoDate.substr(0, 10)} ${isoDate.substr(11, 8)}`);

string foo = yourDateTime.ToUniversalTime()  .ToString("yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'fff'Z'");

//import the function you want to use const {format} = require('date-fns');

const {format} = require('date-fns');
//today's date const today =format(new Date(),'dd.MM.yyyy');
console.log(today);

const {format} = require('date-fns');
const date = new Date();
console.log(date);
console.log(`${format(date, 'dd.MM.yyyy')}`);
console.log(`${format(date, 'yyyy-MM-dd').toString()}`);
console.log(`today is ${format(date, 'EEEE, MMMM yyyy')}`);
console.log(`today is ${format(date, 'EEEE,MMMM do, yyyy hh:mm a')}`);
console.log(`Today's date: ${format(date, 'MMMM, yyyy')}`);
console.log(`Today's date: ${format(date, 'MMMM.do.')}`);
console.log(`Today's date: ${format(date, 'EEEE do HH:mm ')}`);
console.log(`${format(date, 'EEEE,MMMM do, yyyy ppppp')}`);
console.log(`${format(date, 'do MMMM yyyy OOOO')}`);

const {format} = require('date-fns');
//parse a default date value const date = new Date('2020/09/19');
console.log(date);
console.log(`${format(date, 'dd.MM.yyyy')}`);
console.log(`${format(date, 'yyyy-MM-dd').toString()}`);
console.log(`${format(date, 'EEEE, MMMM yyyy')}`);
console.log(`${format(date, 'EEEE,MMMM do, yyyy hh:mm a')}`);
console.log(`${format(date, 'MMMM, yyyy')}`);
console.log(`${format(date, 'MMMM.do.')}`);
console.log(`${format(date, 'EEEE do HH:mm ')}`);
console.log(`${format(date, 'EEEE,MMMM do, yyyy ppppp')}`);
console.log(`${format(date, 'do MMMM yyyy OOOO')}`);

format(date, 'DD.MM.YYYY');
❌ format(date, 'dd.MM.yyyy');

//import the reqqiureds  funtions const {addMinutes,addHours,addDays,addMonths,addYears,format} = require('date-fns');
const date = new Date('2020.09.29 10:12:00');
//add days const sum1 = addDays(date, 4);
//add months const sum2 = addMonths(date, 3);
//add years const sum3 = addYears(date, 3);
//add minutes const sum4 = addMinutes(date, 40);
console.log(format(sum1, 'dd MMMM yyyy HH:mm'));
console.log(format(sum2, 'dd MMMM yyyy HH:mm'));
console.log(format(sum3, 'dd MMMM yyyy HH:mm'));
console.log(format(sum4, 'dd MMMM yyyy HH:mm'));

const date = new Date('2020.09.29 10:12:00');
//sub days const a = subDays(date, 4);
//sub minutes const b = subMinutes(date, 40);
//sub months const c = subMonths(date, 3);
//sub years const d = subYears(date, 2);
console.log(format(a, 'dd MMMM yyyy HH:mm'));
console.log(format(b, 'dd MMMM yyyy HH:mm'));
console.log(format(c, 'dd MMMM yyyy HH:mm'));
console.log(format(d, 'dd MMMM yyyy HH:mm'));

const date = new Date('2019/01/01');
const frenchLocale = require('date-fns/locale/fr');
const format = require('date-fns/format');
const formattedDate = format(date, 'EEEE,MMMM do, yyyy hh:mm a', {
locale: frenchLocale });
console.log(formattedDate);

const newYears = new Date();
const format = require('date-fns/format');
const frenchLocale = require('date-fns/locale/fr');
const russionaLocale = require('date-fns/locale/ca');
const spanishLocale = require('date-fns/locale/es');
const USLocale = require('date-fns/locale/en-US');
const eo = require('date-fns/locale/eo');
console.log( format(newYears, 'EEEE,MMMM do, yyyy hh:mm a', {
locale: frenchLocale}));
console.log( format(newYears, 'EEEE,MMMM do, yyyy hh:mm a', {
locale: eo}));
console.log( format(newYears, 'EEEE,MMMM do, yyyy hh:mm a', {
locale: russionaLocale}));
console.log( format(newYears, 'EEEE,MMMM do, yyyy hh:mm a', {
locale: spanishLocale}));
console.log( format(newYears, 'EEEE,MMMM do, yyyy hh:mm a', {
locale: USLocale}));

const {format,zonedTimeToUtc,} = require("date-fns-tz");
const today = new Date();
// Wed Sep 16 2020 13:25:16 const timeZone = 'Europe/Paris';
// Let's see what time it is Down Under const timeInBrisbane = zonedTimeToUtc(today, timeZone);
console.log(` Default time zone: ${format(today, 'yyyy-MM-dd HH:mm:ss')} Time in Paris: ${format(timeInBrisbane, 'yyyy-MM-dd HH:mm:ss') }`);

const {format,utcToZonedTime,} = require("date-fns-tz");
const today = new Date();
// Wed Sep 16 2020 13:25:16 const timeZone = 'Europe/Paris';
// Let's see what time it is Down Under const timeInBrisbane = utcToZonedTime(today, timeZone);
console.log(` Default time zone: ${format(today, 'yyyy-MM-dd HH:mm:ss')} Time in Paris: ${format(timeInBrisbane, 'yyyy-MM-dd HH:mm:ss') }`);

const { isAfter,addHours, subHours } = require('date-fns');

const { isAfter,addHours, subHours } = require("date-fns");
const date1 = new Date();
const date2 = addHours(new Date(), 5);
const date3 = subHours(new Date(), 5);
console.log(isAfter(date1, date2));
console.log(isAfter(date1, date3));

const { isAfter, isFuture, addHours } = require("date-fns");
const date1 = new Date();
const date2 = addHours(new Date(), 5);
console.log(`Date1 is ${isAfter(date1, date2) ? "after"
: "before"} Date2`);
console.log(`Date2 is ${isFuture(date2) ? "not"
: ""} in the past`);

const { isBefore, addHours, subHours } = require("date-fns");
const date1 = new Date();
const date2 = addHours(new Date(), 5);
const date3 = subHours(new Date(), 5);
console.log(isBefore(date1, date2));
console.log(isBefore(date1, date3));

const { isFuture, addHours, subHours } = require("date-fns");
const date1 = new Date();
const date2 = addHours(new Date(), 5);
const date3 = subHours(new Date(), 5);
console.log(isFuture(date1));
console.log(isFuture(date2));
console.log(isFuture(date3));

const { compareDesc, compareAsc, addMonths, subYears } = require("date-fns");
const date1 = new Date();
const date2 = new Date("2019.04.12");
const date3 = new Date("2020/10/03");
const date4 = new Date("2021,01,19");
const date5 = addMonths(new Date(), 8);
const date6 = subYears(new Date(), 2);
const arrASC = [date1, date2, date3, date4, date5, date6];
const arrDesc = [date1, date2, date3, date4, date5, date6];
console.log(arrASC.sort(compareAsc));
console.log(arrDesc.sort(compareDesc));

const { isWeekend, addHours, subHours } = require("date-fns");
const date1 = new Date("2020,09,19");
const date2 = new Date("2020,09,18");
console.log(isWeekend(date1));
console.log(isWeekend(date2));

const { isDate} = require("date-fns");
// Will return true as the string provided is a date instance const date1 = new Date("2020,09,19");
// Will return true as the string provided is a date instance const date2 = new Date(2020,09,18);
// Will return true as NaN represent an invalid date to return true const date3 = new Date(NaN);
// Will return false as the string provided is not a date instance new Date() is not included const date4 = "2020,09,18";
// Will return true as the string 2020 is a date instance const date5 = new Date("2020");
// Will return true as new Date() will return the current date which is a date instance const date6 = new Date();
// Will return false as the string "not a date"
is a date instance const date7 = "not a date";
console.log(isDate(date1));
console.log(isDate(date2));
console.log(isDate(date3));
console.log(isDate(date4));
console.log(isDate(date5));
console.log(isDate(date6));
console.log(isDate(date7));

const { isValid } = require("date-fns");
const valid_date1 = isValid(new Date('2020, 09, 21')) const valid_date2 = isValid(new Date('2020, 02, 30')) console.log((valid_date1)) console.log((valid_date2))

const {isValid,parse} = require("date-fns");
const validate1 = parse('29.02.2020', 'dd.MM.yyyy', new Date());
const validate2 = parse('30.02.2020', 'dd.MM.yyyy', new Date());
console.log(validate1);
console.log(validate2);
console.log(isValid(validate1));
console.log(isValid(validate2));

const {differenceInDays ,differenceInBusinessDays} = require("date-fns");
const startDate = new Date();
const endDate = new Date("2020,12,25");
const daysBetween = differenceInDays(endDate, startDate);
const workdaysBetween = differenceInBusinessDays(endDate, startDate);
console.log(daysBetween);
console.log(workdaysBetween);

const moment = require('moment');
const today = moment();
console.log(today.format('YYYY MM DD'));

const {format} = require('date-fns');
const today =format(new Date(),'dd.MM.yyyy');
console.log(today);

# Using npm $ npm install date-fns  # Or using yarn $ yarn add date-fns 

const format = require('date-fns/format');
const stPattysDay = new Date('2020/03/17');
const formattedDate1 = format(stPattysDay, 'MM/dd/yyyy');
const formattedDate2 = format(stPattysDay, 'MMMM dd, yyyy');
console.log(formattedDate1);
// =>
"03/17/2020" console.log(formattedDate2);
// =>
"March 17, 2020"

const format = require('date-fns/format');
const addYears = require('date-fns/addYears');
const stPattysDay = new Date('2020/03/17');
const stPattysDayNextYear = addYears(stPattysDay, 1);
const formattedDate = format(stPattysDayNextYear, 'MMMM dd, yyyy');
console.log(formattedDate);
// =>
"March 17, 2021"

const format =  require('date-fns/format');
const russianLocale = require('date-fns/locale/ru');
const stPattysDay = new Date('2020/03/17');
const formattedDate = format(stPattysDay, 'MMMM dd, yyyy', { locale: russianLocale });
console.log(formattedDate);
// =>
"марта 17, 2020"

const format = require('date-fns/format');
const addYears = require('date-fns/addYears');
const differenceInDays = require('date-fns/differenceInDays');
const differenceInBusinessDays = require('date-fns/differenceInBusinessDays') const startDate = new Date('2020/01/01');
const endDate = new Date('2020/12/24');
const daysBetween = differenceInDays(endDate, startDate);
const workdaysBetween = differenceInBusinessDays(endDate, startDate);
console.log(daysBetween);
// =>
358 console.log(workdaysBetween);
// =>
256

const moment = require('moment');
const formattedDate = moment(new Date()).format('MM/DD/YYYY');
console.log(formattedDate);
// =>
"03/17/2020"

const format = require('date-fns/format');
const formattedDate = format(new Date(), 'MM/dd/yyyy');
console.log(formattedDate);
// =>
"03/17/2020"

#2. javascript - date-fns | How do I format to UTC - Stack …

Oct 24, 2019  · Problem. It looks like when I use the format() function, it automatically convert the original UTC time into my timezone (UTC+8). I have been digging through their docs for hours …


import { parseISO, format } from "date-fns";
const time = "2019-10-25T08:10:00Z";
const parsedTime = parseISO(time);
console.log(parsedTime);
// 2019-10-25T08:10:00.000Z const formattedTime = format(parsedTime, "yyyy-MM-dd kk:mm:ss");
console.log(formattedTime);
// 2019-10-25 16:10:00 <-- 8 HOURS OFF!!
format(parsedTime, "yyyy-MM-dd kk:mm:ss", {timeZone: "UTC"});

import { parseISO } from "date-fns";
import { format, utcToZonedTime } from "date-fns-tz";
const time = "2019-10-25T08:10:00Z";
const parsedTime = parseISO(time);
console.log(parsedTime);
// 2019-10-25T08:10:00.000Z const formatInTimeZone = (date, fmt, tz) =>
format(utcToZonedTime(date, tz),

fmt,

{ timeZone: tz });
const formattedTime = formatInTimeZone(parsedTime, "yyyy-MM-dd kk:mm:ss xxx", "UTC");
console.log(formattedTime);
// 2019-10-25 08:10:00 +00:00

import { format, addMinutes } from 'date-fns';
function formatDate(date) {
return format(addMinutes(date, date.getTimezoneOffset()), 'yyyy-MM-dd HH:mm:ss');
}

const date = new Date("2019-10-25T08:10:00Z");
const isoDate = date.toISOString();
console.log(`${isoDate.substr(0, 10)} ${isoDate.substr(11, 8)}`);
import format from 'date-fns/format';
import parseISO from 'date-fns/parseISO';
export const adjustForUTCOffset = date =>
{
return new Date(
date.getUTCFullYear(),
date.getUTCMonth(),
date.getUTCDate(),
date.getUTCHours(),
date.getUTCMinutes(),
date.getUTCSeconds(),
);
};
const formatDate = (dateString) = >
{
const date = parseISO(dateString);
const dateWithOffset = adjustForUTCOffset(date)
return format(dateWithOffset, 'LLL dd, yyyy HH:mm') }
const now = new Date()
const date = format(
new Date(now.toISOString().slice(0, -1)),
'yyyy-MM-dd HH:mm:ss'
)

import { parseISO, format } from "date-fns";
const time = "2019-10-25T08:10:00Z";
const parsedTime = parseISO(new Date(Date.UTC(time)));
const formattedTime = format(parsedTime, "yyyy-MM-dd kk:mm:ss");
const formatDate = new Date().toISOString().substr(0, 19).replace('T', ' ');

#3. [Solved] date-fns | How do I format to UTC | 9to5Answer

Jul 05, 2022  · The date-fns[-tz] libraries stick to the built-in Date data type that carries no TZ info. Some functions treat it as a moment-in-time, but some like format treat it more like a struct of …


const date = new Date("2019-10-25T08:10:00Z");
const isoDate = date.toISOString();
console.log(`${isoDate.substr(0, 10)} ${isoDate.substr(11, 8)}`);

import { parseISO } from "date-fns";
import { format, utcToZonedTime } from "date-fns-tz";
const time = "2019-10-25T08:10:00Z";
const parsedTime = parseISO(time);
console.log(parsedTime);
// 2019-10-25T08:10:00.000Z const formatInTimeZone = (date, fmt, tz) =>
format(utcToZonedTime(date, tz),

fmt,

{ timeZone: tz });
const formattedTime = formatInTimeZone(parsedTime, "yyyy-MM-dd kk:mm:ss xxx", "UTC");
console.log(formattedTime);
// 2019-10-25 08:10:00 +00:00

import { format, addMinutes } from 'date-fns';
function formatDate(date) {
return format(addMinutes(date, date.getTimezoneOffset()), 'yyyy-MM-dd HH:mm:ss');
}
import format from 'date-fns/format';
import parseISO from 'date-fns/parseISO';
export const adjustForUTCOffset = date =>
{
return new Date(
date.getUTCFullYear(),
date.getUTCMonth(),
date.getUTCDate(),
date.getUTCHours(),
date.getUTCMinutes(),
date.getUTCSeconds(),
);
};
const formatDate = (dateString) = >
{
const date = parseISO(dateString);
const dateWithOffset = adjustForUTCOffset(date)
return format(dateWithOffset, 'LLL dd, yyyy HH:mm') }
import { parseISO, format } from "date-fns";
const time = "2019-10-25T08:10:00Z";
const parsedTime = parseISO(time);
console.log(parsedTime);
// 2019-10-25T08:10:00.000Z const formattedTime = format(parsedTime, "yyyy-MM-dd kk:mm:ss");
console.log(formattedTime);
// 2019-10-25 16:10:00 <-- 8 HOURS OFF!!
format(parsedTime, "yyyy-MM-dd kk:mm:ss", {timeZone: "UTC"});

#4. date-fns | How do I format to UTC - CodeForDev

And the date-fns-tz/format function's timeZone input affects only the template chars that print the time zone (XX..X, xx..x, zz..z, OO..O). ... getTimezoneOffset returns the number of minutes …


const date = new Date("2019-10-25T08:10:00Z");
const isoDate = date.toISOString();
console.log(`${isoDate.substr(0, 10)} ${isoDate.substr(11, 8)}`);
import { parseISO } from "date-fns";
import { format, utcToZonedTime } from "date-fns-tz";
const time = "2019-10-25T08:10:00Z";
const parsedTime = parseISO(time);
console.log(parsedTime);
// 2019-10-25T08:10:00.000Z const formatInTimeZone = (date, fmt, tz) =>
format(utcToZonedTime(date, tz),

fmt,

{ timeZone: tz });
const formattedTime = formatInTimeZone(parsedTime, "yyyy-MM-dd kk:mm:ss xxx", "UTC");
console.log(formattedTime);
// 2019-10-25 08:10:00 +00:00
import { format, addMinutes } from 'date-fns';
function formatDate(date) {
return format(addMinutes(date, date.getTimezoneOffset()), 'yyyy-MM-dd HH:mm:ss');
}
import format from 'date-fns/format';
import parseISO from 'date-fns/parseISO';
export const adjustForUTCOffset = date => {
return new Date(
date.getUTCFullYear(),
date.getUTCMonth(),
date.getUTCDate(),
date.getUTCHours(),
date.getUTCMinutes(),
date.getUTCSeconds(),
);
};
const formatDate = (dateString) = > {
const date = parseISO(dateString);
const dateWithOffset = adjustForUTCOffset(date)
return format(dateWithOffset, 'LLL dd, yyyy HH:mm') }

#5. Date fns how do i format to utc | Autoscripts.net

Previous Post Next Post . Date-fns | How do I format to UTC. Problem. It looks like when I use the format() function, it automatically convert the original UTC time into my timezone (UTC+8).


import { parseISO, format } from "date-fns";
const time = "2019-10-25T08:10:00Z";
const parsedTime = parseISO(time);
console.log(parsedTime);
// 2019-10-25T08:10:00.000Z const formattedTime = format(parsedTime, "yyyy-MM-dd kk:mm:ss");
console.log(formattedTime);
// 2019-10-25 16:10:00 <-- 8 HOURS OFF!!

format(parsedTime, "yyyy-MM-dd kk:mm:ss", {timeZone: "UTC"});

import { parseISO } from "date-fns";
import { format, utcToZonedTime } from "date-fns-tz";
const time = "2019-10-25T08:10:00Z";
const parsedTime = parseISO(time);
console.log(parsedTime);
// 2019-10-25T08:10:00.000Z const formatInTimeZone = (date, fmt, tz) =>
format(utcToZonedTime(date, tz),

fmt,

{ timeZone: tz });
const formattedTime = formatInTimeZone(parsedTime, "yyyy-MM-dd kk:mm:ss xxx", "UTC");
console.log(formattedTime);
// 2019-10-25 08:10:00 +00:00

import { format, addMinutes } from 'date-fns';
function formatDate(date) {
return format(addMinutes(date, date.getTimezoneOffset()), 'yyyy-MM-dd HH:mm:ss');
}

const date = new Date("2019-10-25T08:10:00Z");
const isoDate = date.toISOString();
console.log(`${isoDate.substr(0, 10)} ${isoDate.substr(11, 8)}`);

import format from 'date-fns/format';
import parseISO from 'date-fns/parseISO';
export const adjustForUTCOffset = date =>
{
return new Date(
date.getUTCFullYear(),
date.getUTCMonth(),
date.getUTCDate(),
date.getUTCHours(),
date.getUTCMinutes(),
date.getUTCSeconds(),
);
};
const formatDate = (dateString) = >
{
const date = parseISO(dateString);
const dateWithOffset = adjustForUTCOffset(date)
return format(dateWithOffset, 'LLL dd, yyyy HH:mm') }

const now = new Date()
const date = format(
new Date(now.toISOString().slice(0, -1)),
'yyyy-MM-dd HH:mm:ss'
)

import { parseISO, format } from "date-fns";
const time = "2019-10-25T08:10:00Z";
const parsedTime = parseISO(new Date(Date.UTC(time)));
const formattedTime = format(parsedTime, "yyyy-MM-dd kk:mm:ss");

const formatDate = new Date().toISOString().substr(0, 19).replace('T', ' ');

import { format, addMinutes } from 'date-fns';
function formatDate(date) {
return format(addMinutes(date, date.getTimezoneOffset()), 'yyyy-MM-dd HH:mm:ss');
}

import { parseISO } from "date-fns";
import { format, utcToZonedTime } from "date-fns-tz";
const time = "2019-10-25T08:10:00Z";
const parsedTime = parseISO(time);
console.log(parsedTime);
// 2019-10-25T08:10:00.000Z const formatInTimeZone = (date, fmt, tz) =>
format(utcToZonedTime(date, tz),

fmt,

{ timeZone: tz });
const formattedTime = formatInTimeZone(parsedTime, "yyyy-MM-dd kk:mm:ss xxx", "UTC");
console.log(formattedTime);
// 2019-10-25 08:10:00 +00:00

const date = new Date("2019-10-25T08:10:00Z");
const isoDate = date.toISOString();
console.log(`${isoDate.substr(0, 10)} ${isoDate.substr(11, 8)}`);

string foo = yourDateTime.ToUniversalTime()  .ToString("yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'fff'Z'");

//import the function you want to use const {format} = require('date-fns');

const {format} = require('date-fns');
//today's date const today =format(new Date(),'dd.MM.yyyy');
console.log(today);

const {format} = require('date-fns');
const date = new Date();
console.log(date);
console.log(`${format(date, 'dd.MM.yyyy')}`);
console.log(`${format(date, 'yyyy-MM-dd').toString()}`);
console.log(`today is ${format(date, 'EEEE, MMMM yyyy')}`);
console.log(`today is ${format(date, 'EEEE,MMMM do, yyyy hh:mm a')}`);
console.log(`Today's date: ${format(date, 'MMMM, yyyy')}`);
console.log(`Today's date: ${format(date, 'MMMM.do.')}`);
console.log(`Today's date: ${format(date, 'EEEE do HH:mm ')}`);
console.log(`${format(date, 'EEEE,MMMM do, yyyy ppppp')}`);
console.log(`${format(date, 'do MMMM yyyy OOOO')}`);

const {format} = require('date-fns');
//parse a default date value const date = new Date('2020/09/19');
console.log(date);
console.log(`${format(date, 'dd.MM.yyyy')}`);
console.log(`${format(date, 'yyyy-MM-dd').toString()}`);
console.log(`${format(date, 'EEEE, MMMM yyyy')}`);
console.log(`${format(date, 'EEEE,MMMM do, yyyy hh:mm a')}`);
console.log(`${format(date, 'MMMM, yyyy')}`);
console.log(`${format(date, 'MMMM.do.')}`);
console.log(`${format(date, 'EEEE do HH:mm ')}`);
console.log(`${format(date, 'EEEE,MMMM do, yyyy ppppp')}`);
console.log(`${format(date, 'do MMMM yyyy OOOO')}`);

format(date, 'DD.MM.YYYY');
❌ format(date, 'dd.MM.yyyy');

//import the reqqiureds  funtions const {addMinutes,addHours,addDays,addMonths,addYears,format} = require('date-fns');
const date = new Date('2020.09.29 10:12:00');
//add days const sum1 = addDays(date, 4);
//add months const sum2 = addMonths(date, 3);
//add years const sum3 = addYears(date, 3);
//add minutes const sum4 = addMinutes(date, 40);
console.log(format(sum1, 'dd MMMM yyyy HH:mm'));
console.log(format(sum2, 'dd MMMM yyyy HH:mm'));
console.log(format(sum3, 'dd MMMM yyyy HH:mm'));
console.log(format(sum4, 'dd MMMM yyyy HH:mm'));

const date = new Date('2020.09.29 10:12:00');
//sub days const a = subDays(date, 4);
//sub minutes const b = subMinutes(date, 40);
//sub months const c = subMonths(date, 3);
//sub years const d = subYears(date, 2);
console.log(format(a, 'dd MMMM yyyy HH:mm'));
console.log(format(b, 'dd MMMM yyyy HH:mm'));
console.log(format(c, 'dd MMMM yyyy HH:mm'));
console.log(format(d, 'dd MMMM yyyy HH:mm'));

const date = new Date('2019/01/01');
const frenchLocale = require('date-fns/locale/fr');
const format = require('date-fns/format');
const formattedDate = format(date, 'EEEE,MMMM do, yyyy hh:mm a', {
locale: frenchLocale });
console.log(formattedDate);

const newYears = new Date();
const format = require('date-fns/format');
const frenchLocale = require('date-fns/locale/fr');
const russionaLocale = require('date-fns/locale/ca');
const spanishLocale = require('date-fns/locale/es');
const USLocale = require('date-fns/locale/en-US');
const eo = require('date-fns/locale/eo');
console.log( format(newYears, 'EEEE,MMMM do, yyyy hh:mm a', {
locale: frenchLocale}));
console.log( format(newYears, 'EEEE,MMMM do, yyyy hh:mm a', {
locale: eo}));
console.log( format(newYears, 'EEEE,MMMM do, yyyy hh:mm a', {
locale: russionaLocale}));
console.log( format(newYears, 'EEEE,MMMM do, yyyy hh:mm a', {
locale: spanishLocale}));
console.log( format(newYears, 'EEEE,MMMM do, yyyy hh:mm a', {
locale: USLocale}));

const {format,zonedTimeToUtc,} = require("date-fns-tz");
const today = new Date();
// Wed Sep 16 2020 13:25:16 const timeZone = 'Europe/Paris';
// Let's see what time it is Down Under const timeInBrisbane = zonedTimeToUtc(today, timeZone);
console.log(` Default time zone: ${format(today, 'yyyy-MM-dd HH:mm:ss')} Time in Paris: ${format(timeInBrisbane, 'yyyy-MM-dd HH:mm:ss') }`);

const {format,utcToZonedTime,} = require("date-fns-tz");
const today = new Date();
// Wed Sep 16 2020 13:25:16 const timeZone = 'Europe/Paris';
// Let's see what time it is Down Under const timeInBrisbane = utcToZonedTime(today, timeZone);
console.log(` Default time zone: ${format(today, 'yyyy-MM-dd HH:mm:ss')} Time in Paris: ${format(timeInBrisbane, 'yyyy-MM-dd HH:mm:ss') }`);

const { isAfter,addHours, subHours } = require('date-fns');

const { isAfter,addHours, subHours } = require("date-fns");
const date1 = new Date();
const date2 = addHours(new Date(), 5);
const date3 = subHours(new Date(), 5);
console.log(isAfter(date1, date2));
console.log(isAfter(date1, date3));

const { isAfter, isFuture, addHours } = require("date-fns");
const date1 = new Date();
const date2 = addHours(new Date(), 5);
console.log(`Date1 is ${isAfter(date1, date2) ? "after"
: "before"} Date2`);
console.log(`Date2 is ${isFuture(date2) ? "not"
: ""} in the past`);

const { isBefore, addHours, subHours } = require("date-fns");
const date1 = new Date();
const date2 = addHours(new Date(), 5);
const date3 = subHours(new Date(), 5);
console.log(isBefore(date1, date2));
console.log(isBefore(date1, date3));

const { isFuture, addHours, subHours } = require("date-fns");
const date1 = new Date();
const date2 = addHours(new Date(), 5);
const date3 = subHours(new Date(), 5);
console.log(isFuture(date1));
console.log(isFuture(date2));
console.log(isFuture(date3));

const { compareDesc, compareAsc, addMonths, subYears } = require("date-fns");
const date1 = new Date();
const date2 = new Date("2019.04.12");
const date3 = new Date("2020/10/03");
const date4 = new Date("2021,01,19");
const date5 = addMonths(new Date(), 8);
const date6 = subYears(new Date(), 2);
const arrASC = [date1, date2, date3, date4, date5, date6];
const arrDesc = [date1, date2, date3, date4, date5, date6];
console.log(arrASC.sort(compareAsc));
console.log(arrDesc.sort(compareDesc));

const { isWeekend, addHours, subHours } = require("date-fns");
const date1 = new Date("2020,09,19");
const date2 = new Date("2020,09,18");
console.log(isWeekend(date1));
console.log(isWeekend(date2));

const { isDate} = require("date-fns");
// Will return true as the string provided is a date instance const date1 = new Date("2020,09,19");
// Will return true as the string provided is a date instance const date2 = new Date(2020,09,18);
// Will return true as NaN represent an invalid date to return true const date3 = new Date(NaN);
// Will return false as the string provided is not a date instance new Date() is not included const date4 = "2020,09,18";
// Will return true as the string 2020 is a date instance const date5 = new Date("2020");
// Will return true as new Date() will return the current date which is a date instance const date6 = new Date();
// Will return false as the string "not a date"
is a date instance const date7 = "not a date";
console.log(isDate(date1));
console.log(isDate(date2));
console.log(isDate(date3));
console.log(isDate(date4));
console.log(isDate(date5));
console.log(isDate(date6));
console.log(isDate(date7));

const { isValid } = require("date-fns");
const valid_date1 = isValid(new Date('2020, 09, 21')) const valid_date2 = isValid(new Date('2020, 02, 30')) console.log((valid_date1)) console.log((valid_date2))

const {isValid,parse} = require("date-fns");
const validate1 = parse('29.02.2020', 'dd.MM.yyyy', new Date());
const validate2 = parse('30.02.2020', 'dd.MM.yyyy', new Date());
console.log(validate1);
console.log(validate2);
console.log(isValid(validate1));
console.log(isValid(validate2));

const {differenceInDays ,differenceInBusinessDays} = require("date-fns");
const startDate = new Date();
const endDate = new Date("2020,12,25");
const daysBetween = differenceInDays(endDate, startDate);
const workdaysBetween = differenceInBusinessDays(endDate, startDate);
console.log(daysBetween);
console.log(workdaysBetween);

const moment = require('moment');
const today = moment();
console.log(today.format('YYYY MM DD'));

const {format} = require('date-fns');
const today =format(new Date(),'dd.MM.yyyy');
console.log(today);

# Using npm $ npm install date-fns  # Or using yarn $ yarn add date-fns 

const format = require('date-fns/format');
const stPattysDay = new Date('2020/03/17');
const formattedDate1 = format(stPattysDay, 'MM/dd/yyyy');
const formattedDate2 = format(stPattysDay, 'MMMM dd, yyyy');
console.log(formattedDate1);
// =>
"03/17/2020" console.log(formattedDate2);
// =>
"March 17, 2020"

const format = require('date-fns/format');
const addYears = require('date-fns/addYears');
const stPattysDay = new Date('2020/03/17');
const stPattysDayNextYear = addYears(stPattysDay, 1);
const formattedDate = format(stPattysDayNextYear, 'MMMM dd, yyyy');
console.log(formattedDate);
// =>
"March 17, 2021"

const format =  require('date-fns/format');
const russianLocale = require('date-fns/locale/ru');
const stPattysDay = new Date('2020/03/17');
const formattedDate = format(stPattysDay, 'MMMM dd, yyyy', { locale: russianLocale });
console.log(formattedDate);
// =>
"марта 17, 2020"

const format = require('date-fns/format');
const addYears = require('date-fns/addYears');
const differenceInDays = require('date-fns/differenceInDays');
const differenceInBusinessDays = require('date-fns/differenceInBusinessDays') const startDate = new Date('2020/01/01');
const endDate = new Date('2020/12/24');
const daysBetween = differenceInDays(endDate, startDate);
const workdaysBetween = differenceInBusinessDays(endDate, startDate);
console.log(daysBetween);
// =>
358 console.log(workdaysBetween);
// =>
256

const moment = require('moment');
const formattedDate = moment(new Date()).format('MM/DD/YYYY');
console.log(formattedDate);
// =>
"03/17/2020"

const format = require('date-fns/format');
const formattedDate = format(new Date(), 'MM/dd/yyyy');
console.log(formattedDate);
// =>
"03/17/2020"

#6. Format a duration ( from seconds ) using date-fns


import {  intervalToDuration } from 'date-fns'  const seconds = 10000  intervalToDuration({ start: 0, end: seconds * 1000 }) // { hours: 2, minutes: 46, seconds: 40 } 
import {  intervalToDuration } from 'date-fns'  const seconds = 1807 const duration = intervalToDuration({ start: 0, end: seconds * 1000 }) // { minutes: 30, seconds: 7 }  const formatted = `${duration.minutes}:${duration.seconds}` // 30:7 
import {  intervalToDuration } from 'date-fns'  const seconds = 1807 const duration = intervalToDuration({ start: 0, end: seconds * 1000 }) // { minutes: 30, seconds: 7 }  const zeroPad = (num) =>
String(num).padStart(2, '0') const formatted = `${zeroPad(duration.minutes)}:${zeroPad(duration.seconds)}` // 30:07
import {  intervalToDuration } from 'date-fns'  const seconds = 1807 const duration = intervalToDuration({ start: 0, end: seconds * 1000 }) // { minutes: 30, seconds: 7 }  const zeroPad = (num) =>
String(num).padStart(2, '0') const formatted = [
duration.hours,
duration.minutes,
duration.seconds, ] .filter(Boolean) .map(zeroPad) .join(':') // 30:07
import { intervalToDuration, formatDuration } from "date-fns";
const seconds = 1807;
const duration = intervalToDuration({ start: 0, end: seconds * 1000 });
// { minutes: 30, seconds: 7 } const zeroPad = (num) =>
String(num).padStart(2, "0");
const formatted = formatDuration(duration, {
format: ["minutes", "seconds"],
// format: ["hours", "minutes", "seconds"],
zero: true,
delimiter: ":",
locale: {
formatDistance: (_token, count) =>
zeroPad(count)
} });
// 30:07
import { formatDistance } from 'date-fns'  const duration = s =>
formatDistance(0, s * 1000, { includeSeconds: true }) duration(50) // 'less than a minute' duration(1000) // '17 minutes'
import moment from 'moment'
const duration = s =>
moment.duration(s, 'seconds').humanize() duration(50) // 'a minute' duration(1000) // '17 minutes'
var input = document.getElementById('seconds');
var output = document.getElementById('out');
output.innerText = formattedTime(input.value);
input.addEventListener('input', function() {
output.innerText = formattedTime(input.value);
});
function formattedTime(seconds) {
var helperDate = dateFns.addSeconds(new Date(0), seconds);
return dateFns.format(helperDate, 'mm:ss');
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/date-fns/1.26.0/date_fns.min.js"></script>
<input type="number" id="seconds" value="1807">
<pre id="out"></pre>
import { addHours, getMinutes, getHours, getSeconds } from 'date-fns';
export const convertToDuration = (secondsAmount: number) =>
{
const normalizeTime = (time: string): string =>
time.length === 1 ? `0${time}` : time;
const SECONDS_TO_MILLISECONDS_COEFF = 1000;
const MINUTES_IN_HOUR = 60;
const milliseconds = secondsAmount * SECONDS_TO_MILLISECONDS_COEFF;
const date = new Date(milliseconds);
const timezoneDiff = date.getTimezoneOffset() / MINUTES_IN_HOUR;
const dateWithoutTimezoneDiff = addHours(date, timezoneDiff);
const hours = normalizeTime(String(getHours(dateWithoutTimezoneDiff)));
const minutes = normalizeTime(String(getMinutes(dateWithoutTimezoneDiff)));
const seconds = normalizeTime(String(getSeconds(dateWithoutTimezoneDiff)));
const hoursOutput = hours !== '00' ? `${hours}:` : '';
return `${hoursOutput}${minutes}:${seconds}`;
};

#7. Formatted dates in Node/JavaScript to UTC - Stack Overflow


const d = format(new Date('2020-09-15 11:52:22.000'), 'dd MMM yyyy HH:mm:ss') 

new Date('2020-09-15 11:52:22.000') 

const dateFns = require("date-fns");
const { zonedTimeToUtc, utcToZonedTime, format } = require('date-fns-tz');
let timestamp = '2020-09-15 11:52:22.000';
let tz = 'Z';
let date = dateFns.parse(timestamp + tz, 'yyyy-MM-dd HH:mm:ss.SSSX', new Date());
// Show timestamp was parsed as UTC console.log(date.toISOString());
// 2020-09-15T11:52:22.000Z // Produce UTC output - need to set timezone first let utcDate = utcToZonedTime(date, 'UTC');
// Manually add timezone to formatted string console.log(format(utcDate, 'd MMM yyyy HH:mm \'UTC\'', 'UTC'));
// 15 Sep 2020 11:52 UTC

const parsedDate = parse('2020-09-15 11:52:22.000', 'yyyy-MM-dd HH:mm:ss.SSS', new Date()).toUTCString();
// Tue, 15 Sep 2020 09:52:22 GMT // or simply // new Date('2020-09-15 11:52:22.000').toUTCString();
// format a new date starting from UTC format // new Date(parsedDate) -->
Tue Sep 15 2020 11:52:22 GMT+0200 const date = format(new Date(parsedDate), 'dd MMM yyyy HH:mm:ss');
moment().format('Do MMMM YYYY, h:mm:ss');

#8. javascript - date-fns | How do I format to UTC - Stack Overflow


import { parseISO, format } from "date-fns";
const time = "2019-10-25T08:10:00Z";
const parsedTime = parseISO(time);
console.log(parsedTime);
// 2019-10-25T08:10:00.000Z const formattedTime = format(parsedTime, "yyyy-MM-dd kk:mm:ss");
console.log(formattedTime);
// 2019-10-25 16:10:00 <-- 8 HOURS OFF!!
format(parsedTime, "yyyy-MM-dd kk:mm:ss", {timeZone: "UTC"});

import { parseISO } from "date-fns";
import { format, utcToZonedTime } from "date-fns-tz";
const time = "2019-10-25T08:10:00Z";
const parsedTime = parseISO(time);
console.log(parsedTime);
// 2019-10-25T08:10:00.000Z const formatInTimeZone = (date, fmt, tz) =>
format(utcToZonedTime(date, tz),

fmt,

{ timeZone: tz });
const formattedTime = formatInTimeZone(parsedTime, "yyyy-MM-dd kk:mm:ss xxx", "UTC");
console.log(formattedTime);
// 2019-10-25 08:10:00 +00:00

import { format, addMinutes } from 'date-fns';
function formatDate(date) {
return format(addMinutes(date, date.getTimezoneOffset()), 'yyyy-MM-dd HH:mm:ss');
}

const date = new Date("2019-10-25T08:10:00Z");
const isoDate = date.toISOString();
console.log(`${isoDate.substr(0, 10)} ${isoDate.substr(11, 8)}`);
import format from 'date-fns/format';
import parseISO from 'date-fns/parseISO';
export const adjustForUTCOffset = date =>
{
return new Date(
date.getUTCFullYear(),
date.getUTCMonth(),
date.getUTCDate(),
date.getUTCHours(),
date.getUTCMinutes(),
date.getUTCSeconds(),
);
};
const formatDate = (dateString) = >
{
const date = parseISO(dateString);
const dateWithOffset = adjustForUTCOffset(date)
return format(dateWithOffset, 'LLL dd, yyyy HH:mm') }
const now = new Date()
const date = format(
new Date(now.toISOString().slice(0, -1)),
'yyyy-MM-dd HH:mm:ss'
)

import { parseISO, format } from "date-fns";
const time = "2019-10-25T08:10:00Z";
const parsedTime = parseISO(new Date(Date.UTC(time)));
const formattedTime = format(parsedTime, "yyyy-MM-dd kk:mm:ss");
const formatDate = new Date().toISOString().substr(0, 19).replace('T', ' ');

#9. GitHub - date-fns/utc: date-fns UTC utils


npm install @date-fns/utc --save

import { UTCDate } from "@date-fns/utc"; import { addHours } from "date-fns";  // Given that the system time zone is America/Los_Angeles // where DST happens at Sunday, 13 March 2022, 02:00:00  // Using system time zone will produce 03:00 instead of 02:00 because of DST: const date = new Date(2022, 2, 13); addHours(date, 2).toString(); //=>
'Sun Mar 13 2022 03:00:00 GMT-0700 (Pacific Daylight Time)'
// Using UTC will provide expected 02:00: const utcDate = new UTCDate(2022, 2, 13); addHours(utcDate, 2).toString(); //=>
'Sun Mar 13 2022 02:00:00 GMT+0000 (Coordinated Universal Time)'

import { UTCDateMini, UTCDate } from "@date-fns/utc";  // UTCDateMini will format date-time in the system time zone: new UTCDateMini(2022, 2, 13).toString(); //=>
'Sat Mar 12 2022 16:00:00 GMT-0800 (Pacific Standard Time)'
// UTCDate will format date-time in the UTC, like expected: new UTCDate(2022, 2, 13).toString(); //=>
'Sun Mar 13 2022 00:00:00 GMT+0000 (Coordinated Universal Time)'

#10. Proper way to parse a date as UTC using date-fns

Dec 03, 2020  · Yes, parseJSON from date-fns finally worked! I got date strings from SQLite that are in UTC, without explicit timezone. Parsing those date strings using date-fns parse or …


2020-12-03 08:30:00 2020-12-03 08:40:00 ... 

const toParse = "2020-12-03 08:40:00"
parse(toParse, 'yyyy-MM-dd HH:mm:ss', new Date()).toISOString()

>
"2020-12-03T07:40:00Z"

>
"2020-12-03T08:40:00Z".

const toParse = "2020-12-03 08:40:00"
parse(toParse + '+00', 'yyyy-MM-dd HH:mm:ss' + 'X', new Date()).toISOString()

>
"2020-12-03T08:40:00Z".

// Setup var {parse} = require('date-fns');
var {zonedTimeToUtc} = require('date-fns-tz');
// Parse an ISO 8601 timestamp recognised by date-fns let loc = 'UTC';
let s1
= '2020-12-03 08:30:00';
let utcDate = zonedTimeToUtc(s1, loc);
// Show UTC ISO 8601 timestamp console.log(utcDate.toISOString());
// "2020-12-03T08:30:00.000Z"
// Parse non–standard format yyyyMMdd let s2 = '20210119';
let fIn = 'yyyyMMdd';
let d = zonedTimeToUtc(parse(s2, fIn, new Date()), loc);
console.log(d.toISOString());
// "2021-01-19T00:00:00.000Z"```

import { parseJSON } from 'date-fns';
const utcDate = parseJSON('2020-12-03 08:40:00');
// Thu Dec 03 2020 19:40:00 GMT+1100 (Australian Eastern Daylight Time)

 it('should parse polish date', async () =>
{
expect.assertions(1)
const dateWithoutTime = '29 gru 2003'
const parsed = parse(dateWithoutTime, 'd LLL yyyy', new Date(), {
locale: pl,
})
const dateUTC = zonedTimeToUtc(parsed, 'UTC')
expect(dateUTC.toISOString()).toStrictEqual('2003-12-29T00:00:00.000Z')
})

#11. date-fns | How do I format to UTC


import { parseISO, format } from "date-fns";
const time = "2019-10-25T08:10:00Z";
const parsedTime = parseISO(time);
console.log(parsedTime);
// 2019-10-25T08:10:00.000Z const formattedTime = format(parsedTime, "yyyy-MM-dd kk:mm:ss");
console.log(formattedTime);
// 2019-10-25 16:10:00 <-- 8 HOURS OFF!!
format(parsedTime, "yyyy-MM-dd kk:mm:ss", {timeZone: "UTC"});

import { parseISO } from "date-fns";
import { format, utcToZonedTime } from "date-fns-tz";
const time = "2019-10-25T08:10:00Z";
const parsedTime = parseISO(time);
console.log(parsedTime);
// 2019-10-25T08:10:00.000Z const formatInTimeZone = (date, fmt, tz) =>
format(utcToZonedTime(date, tz),

fmt,

{ timeZone: tz });
const formattedTime = formatInTimeZone(parsedTime, "yyyy-MM-dd kk:mm:ss xxx", "UTC");
console.log(formattedTime);
// 2019-10-25 08:10:00 +00:00

import { format, addMinutes } from 'date-fns';
function formatDate(date) {
return format(addMinutes(date, date.getTimezoneOffset()), 'yyyy-MM-dd HH:mm:ss');
}

const date = new Date("2019-10-25T08:10:00Z");
const isoDate = date.toISOString();
console.log(`${isoDate.substring(0, 10)} ${isoDate.substring(11, 19)}`);
import format from 'date-fns/format';
import parseISO from 'date-fns/parseISO';
export const adjustForUTCOffset = date =>
{
return new Date(
date.getUTCFullYear(),
date.getUTCMonth(),
date.getUTCDate(),
date.getUTCHours(),
date.getUTCMinutes(),
date.getUTCSeconds(),
);
};
const formatDate = (dateString) = >
{
const date = parseISO(dateString);
const dateWithOffset = adjustForUTCOffset(date)
return format(dateWithOffset, 'LLL dd, yyyy HH:mm') }
const now = new Date()
const date = format(
new Date(now.toISOString().slice(0, -1)),
'yyyy-MM-dd HH:mm:ss'
)

import { parseISO, format } from "date-fns";
const time = "2019-10-25T08:10:00Z";
const parsedTime = parseISO(new Date(Date.UTC(time)));
const formattedTime = format(parsedTime, "yyyy-MM-dd kk:mm:ss");
const formatDate = new Date().toISOString().substr(0, 19).replace('T', ' ');

Please leave your answer here: