I have a DateTimePicker with custom format 'LT'. When I get the value, I get 'YYYY-MM-DD' format instead of ISO-8601.
$('#init').datetimepicker({
format: 'LT',
...
});
var init = $('#init').data("DateTimePicker").viewDate().format();
console.log(init); // Shows 'YYYY-MM-DD' and I want ISO-8601
If I don't format the init variable, I get a moment object with these values:
init {
_ambigTime: true
_ambigZone: true
_d: Wed Mar 20 2019 10:15:00 GMT+0100 (CET)
_f: "YYYY-MM-DD"
_fullCalendar: true
_i: "2019-03-20"
_isAMomentObject: true
_isUTC: true
_isValid: true
... }
I don't know why it has 'YYYY-MM-DD' format declared.
Thanks in advance!
-- EDIT:
I'm using Eonasdan/Bootstrap-DateTimePicker
I tried to cast the init variable with .toISOString() and I still get YYYY-MM-DD format.
It fixed parsing to UTC:
$('#init').data("DateTimePicker").viewDate().utc().format()
Related
I have a date object in my state coming from a react-datepicker component.
Sat Aug 28 2021 18:00:00 GMT+0530 (India Standard Time)
On Submit I am trying to pass this to my Node backend
try {
const responseData = await sendRequest('http://localhost:5000/challenge/createChallenge', 'POST',
JSON.stringify({
location: selectedOption,
format: selectedOption1,
date: selectedDate,
opponent: props.initialValues
}),
{
'Content-Type': 'application/json',
Authorization: 'Bearer ' + auth.token
})
Using Stringify, it loses its form. The date loses 5.5 hours and becomes a string.
date: '2021-08-24T12:30:00.000Z'
how do I preserve the original IST format while sending it across? I tried removing the Json.stringify but it keeps erroring me out.
I think if you send a date object to backend as below, your problem will be sorted out
date: new Date(yourDate)
and remove that JSON.stringify.
Not sure if this is the right solution but I passed the data with to.String() and its now getting received accurately in NODE. Thanks.
JSON.stringify({
location: selectedOption,
format: selectedOption1,
date: selectedDate.toString(),
opponent: props.initialValues
}),
I'm trying to set the some data inside of cookie using js-cookie.
but somehow it's not setting in the cookie. following is my code:
const setCookie = (name: string, value: string, expires: Date) => {
Cookies.set(name, value, {expires})
}
and this is the result when I console.log this line :
UserId=1; path=/; expires=Thu, 09 Apr 2020 15:26:37 GMT
I thought that path=/ is the problem, so I've tried to set the path as well, but didn't work.
Does anyone have idea why is not setting into the cookie?
Updated:
data passed to name, value, expires are :
UserId, 1, Thu Apr 09 2020 11:26:37 GMT-0400 (Eastern Daylight Time)
Expires parameter should be a number which indicate how much days until your cookie will expire
just update your function as follow
const setCookie = (name: string, value: string, expires: number) => {
Cookies.set(name, value, {expires})
}
I'm trying to play with asyncData in Nuxt.js and it seems to me that not every property could be placed here as is. For example instances of Moment (moment.js) and DateTime (luxon), they are serialized into string:
import { DateTime } from 'luxon'
const moment = require('moment')
...
asyncData(context) {
return {
date1: moment(),
date2: DateTime.local(),
pureDate: new Date()
}
},
mounted() {
console.log(typeof this.date1) // string ("2019-06-11T16:24:00.746Z")
console.log(typeof this.date2) // string ("2019-06-13T19:24:00.748+03:00")
console.log(typeof this.pureDate) // object (Thu Jun 13 2019 19:24:00 GMT+0300 (Moscow Standard Time))
}
some other complex objects properties raise warn:
Cannot stringify arbitrary non-POJOs OpenPositions
someone please explain me this behavior
sandbox snippet
demo repo on github
i try convert string to moment and check is same.
protected showEvent(event: IEvent, hour: Moment): boolean {
let formatDate: Moment = moment(event.futureDate);
console.log('--> formatDate', formatDate);
console.log('--> hour', hour);
return formatDate.isSame(hour, "hour"); // return true is same
}
this console result
--> formatDate: Moment {_isAMomentObject: true, _i: "07-24-2017 07:00:00.000", _isUTC: false, _pf: Object, _locale: Locale…}_d: Mon Jul 24 2017 07:00:00 GMT+0200 (CEST)_i: "07-24-2017 07:00:00.000"}
--> hour: Moment {_isAMomentObject: true, _isUTC: false, _pf: Object, _locale: Locale, _d: Tue Jul 25 2017 07:00:00 GMT+0200 (CEST)…}
How can I convert the date to see if the time is the same?
edit: the whole looks like this
protected showEvent(event: IEvent, hour: Moment): boolean {
return moment(event.futureDate).hour() == hour.hours()
}
Try comparing the hour value alone.
return formatDate.hours() == hour.hours()
If you are looking to compare the entire date you can compare the other values e.g. minutes()
Hi I am using Ember+moment.js to format date in my ember helpers.
I am getting the following date from the service
Tue Aug 23 2016 09:43:53 GMT+0200 (W. Europe Daylight Time)
In my ember helper class i am able to format date using following code :
var formattedDate = moment(date).format('DD/MM/YYYY h:mm a');
I am getting the following output :
23/08/2016 9:43 am
Expected Output : 23/08/2016 9:43 am GMT
How can i specify the timezone flag in the format function?
Any help should be appreciated.
Install ember-moment - ember install ember-moment
Install ember-cli-moment-shim - ember install ember-cli-moment-shim
stop and start ember server
To enable moment timezone, need to include moment:{ includeTimezone: 'all' } in config\environment.js
/* jshint node: true */
module.exports = function(environment) {
var ENV = {
modulePrefix: 'App-Name',
environment: environment,
baseURL: '/',
locationType: 'auto',
moment: {
// Options:
// 'all' - all years, all timezones
// '2010-2020' - 2010-2020, all timezones
// 'none' - no data, just timezone API
includeTimezone: 'all'
},
EmberENV: {
FEATURES: {
// Here you can enable experimental features on an ember canary build
// e.g. 'with-controller': true
}
},
APP: {
// Here you can pass flags/options to your application instance
// when it is created
}
};
return ENV;
};
and then you can start use tz function and to get abbreviated time zone name you can include z flag in the format.
moment().tz('Asia/Calcutta').format('DD/MM/YYYY h:mm a z')