momentjs

Some code only works while chrome debugger is active

你。 提交于 2020-07-09 07:36:13
问题 I'm working on a react-native application and I'm trying to format a date using moment. Dates look like "02-16-2016 09:04:23" function formatTime(date){ var formattedDate = moment(date).format('MM:ss A'); return formattedDate; } Works fine if the chrome debugger is active. But if I disable it, all I get is "invalid date" Same thing with a decoding function I'm using var that = this; MessagesService.getMessageBody(selectedMessage) .then(function(messageBody){ var decodedData = window.atob

How to set language globally for moment.js

谁说我不能喝 提交于 2020-07-05 03:09:29
问题 I get for example: 1day ago. What I need is to set for different language, for example for de . Any suggestion how can I do that? moment(Date.now()).fromNow() I tried this: <script> var moment = moment(); moment.locale('de'); </script> but get an error: moment is not a function 回答1: See official docs on how changing locale globally. Note that you have to import locale data (e.g. moment-with-locales.min.js) Here a working example: moment.locale('de'); console.log(moment(Date.now()).fromNow());

How to set language globally for moment.js

烂漫一生 提交于 2020-07-05 03:08:16
问题 I get for example: 1day ago. What I need is to set for different language, for example for de . Any suggestion how can I do that? moment(Date.now()).fromNow() I tried this: <script> var moment = moment(); moment.locale('de'); </script> but get an error: moment is not a function 回答1: See official docs on how changing locale globally. Note that you have to import locale data (e.g. moment-with-locales.min.js) Here a working example: moment.locale('de'); console.log(moment(Date.now()).fromNow());

How to set language globally for moment.js

假装没事ソ 提交于 2020-07-05 03:07:57
问题 I get for example: 1day ago. What I need is to set for different language, for example for de . Any suggestion how can I do that? moment(Date.now()).fromNow() I tried this: <script> var moment = moment(); moment.locale('de'); </script> but get an error: moment is not a function 回答1: See official docs on how changing locale globally. Note that you have to import locale data (e.g. moment-with-locales.min.js) Here a working example: moment.locale('de'); console.log(moment(Date.now()).fromNow());

Converting Excel Time to moment.js

微笑、不失礼 提交于 2020-06-28 06:56:05
问题 I have an Electron app where an Excel-Sheet with a couple of columns containing time values needs to be imported. In my app those values are converted in a loop to momentjs object for further manipulation: x['Time'] = moment(x['Time'], ['HH:mm','HH:mm:ss']).format('HH:mm:ss'); This works fine as long the Excel contains time values formatted as text. But if the Excel is set up the way it's meant to be, then the value of the Cell is a Number between 0 and 1 (Excel counts time internally as

moment-timezones.js, how to convert date in spesific timezone to utc, disregarding my local timezone?

China☆狼群 提交于 2020-06-28 06:22:53
问题 my system uses timezone UTC+03:00 , im trying to get a date in string format, represented by NY timezone, and convert it to a Date object in utc const dateInNY = moment.tz(xlsxDate, "M/D/YYYY h:mm a", "America/New_York") .tz("Z").toDate(); doesnt work correctly how am i even suppose to convert to utc time? -----------edit--------------- i got it to work, using the timezone "Africa/Accra" , where UTC offset is 0, and ther is no daylight savings time: moment.tz(xlsxDate, "M/D/YYYY h:mm a",

Vue momentjs update relative time in real time

a 夏天 提交于 2020-06-22 17:48:20
问题 How I can do update relative time from momentjs in real time for user? I have computed: computed: { ago() { return moment().fromNow(); }, } And when I use in component this: <span class="text-muted pr-2" v-text="ago"></span> I get static text: a few seconds ago , how update this text without page reloading? I want see: a minute ago , a two minutes ago e.t.c.. How I can do this in real time for user? 回答1: Since moment().fromNow() isn't reactive so you will not see any change,to deal with we

Vue momentjs update relative time in real time

谁都会走 提交于 2020-06-22 17:47:35
问题 How I can do update relative time from momentjs in real time for user? I have computed: computed: { ago() { return moment().fromNow(); }, } And when I use in component this: <span class="text-muted pr-2" v-text="ago"></span> I get static text: a few seconds ago , how update this text without page reloading? I want see: a minute ago , a two minutes ago e.t.c.. How I can do this in real time for user? 回答1: Since moment().fromNow() isn't reactive so you will not see any change,to deal with we

How to get previous date in javascript

好久不见. 提交于 2020-06-16 22:33:45
问题 I have one date but i want to get previous date from that.How we can do using javascript or momentjs? Demo:https://stackblitz.com/edit/js-ykswiz?file=index.js date format dd-mm-yyyy. Example: var date1=new Date("08-06-2020"); console.log("Prev Date="+date1.getDate() - 1);// Prev Date=07-06-2020 var date2=new Date("01-06-2020"); console.log("Prev Date="+date2.getDate() - 1);// Prev Date=31-05-2020 var date3=new Date("01-01-2021"); console.log("Prev Date="+date3.getDate() - 1);// Prev Date=31

How to get previous date in javascript

心已入冬 提交于 2020-06-16 22:31:09
问题 I have one date but i want to get previous date from that.How we can do using javascript or momentjs? Demo:https://stackblitz.com/edit/js-ykswiz?file=index.js date format dd-mm-yyyy. Example: var date1=new Date("08-06-2020"); console.log("Prev Date="+date1.getDate() - 1);// Prev Date=07-06-2020 var date2=new Date("01-06-2020"); console.log("Prev Date="+date2.getDate() - 1);// Prev Date=31-05-2020 var date3=new Date("01-01-2021"); console.log("Prev Date="+date3.getDate() - 1);// Prev Date=31