momentjs

Where to apply my moment() function in a react component?

六月ゝ 毕业季﹏ 提交于 2020-01-03 13:56:08
问题 I am trying to do a clock component, simply to give the date and time in local format in a webpage. I imported MomentJS using the command line npm i moment --save in my webpack environment. Next I wrote this in my Clock.jsx component (mostly based on the React example on the website). import React from 'react'; import Moment from 'moment'; export default class Clock extends React.Component { constructor(props) { super(props); this.state = { dateTimestamp : Date.now() }; } tick = () => { this

Get available time ranges from an array of busy time ranges

跟風遠走 提交于 2020-01-03 03:28:09
问题 Lets say you have an array of BUSY time ranges for a meeting [{'start':'9:00 AM', 'end':'10:00 AM'}, {'start':'12:00 PM', 'end':'2:00 PM'}, {'start':'5:00 AM', 'end':'7:00 PM'}] I would like to get in return an array of AVAILABLE times in a 24 hour frame, that are the opposite of the above times. Like... [{'start':'00:00 AM', 'end':'9:00 AM'}, {'start':'10:00 AM', 'end':'12:00 PM'}, {'start':'2:00 PM', 'end':'5:00 PM'}, {'start':'7:00 PM', 'end':'11:59 PM'}] I have tried using moment.js as

Use require.js to run common code before module is required

左心房为你撑大大i 提交于 2020-01-02 06:58:29
问题 I'm using Moment.js on a few different pages in an international site. Each page uses require.js to require in Moment. Moment allows you to set the locale to display dates in that locales format. However, this code has to be run on every page Moment is loaded (since I'm never sure which page the user loads first). var Moment = require('moment'); // configure locale What I want to do is move the code to configure the locale to something like a pre-require step so that I don't have to remember

moment.js thinks that 2013-12-31 is week 1, not week 53

北城以北 提交于 2020-01-02 06:49:29
问题 The moment.js library is awesome, and I use it almost all the time, but I recently ran into something interesting. I'm trying to plot data by week of the year, and one of the data points was 2013-12-31, moment.js tells me this is week 1? Is there a better way to handle this? either with 53, null, -1, or something? moment('2013-12-31').week() (returns) 1 I thought maybe using isoWeek or format would get around this, but they all return the same value of 1, despite the documentation saying it

moment.js thinks that 2013-12-31 is week 1, not week 53

怎甘沉沦 提交于 2020-01-02 06:49:07
问题 The moment.js library is awesome, and I use it almost all the time, but I recently ran into something interesting. I'm trying to plot data by week of the year, and one of the data points was 2013-12-31, moment.js tells me this is week 1? Is there a better way to handle this? either with 53, null, -1, or something? moment('2013-12-31').week() (returns) 1 I thought maybe using isoWeek or format would get around this, but they all return the same value of 1, despite the documentation saying it

Extracting utcOffset from an ISO String with Moment.js

て烟熏妆下的殇ゞ 提交于 2020-01-02 06:48:08
问题 Using moment.js, I'm attempting to extract the offset from an ISO date string so I can use the offset later when formatting an epoch timestamp to ensure the conversion of the timestamp is in the same timezone. Even though the offset in the string is -0400, the result is always 0; var currentTime = "2015-03-18T16:10:00.001-0400"; var utcOffset = moment(currentTime).utcOffset(); // 0 I've attempted to use parseZone() as well without success. Is there a way to extract -0400 from the string so I

Moment.js sets dates to 1 day behind

折月煮酒 提交于 2020-01-02 05:46:20
问题 I am using 2.22.1 to format dates. When i put in a date that comes from a date selector, moment will put the date back one day. For example, when I try to format a date in the following way: Example 1: const day = new Date(value).getDate(); const month = new Date(value).getMonth(); const fullYear = new Date(value).getFullYear(); console.log('day', day); // 7 console.log('month', month); // 5 console.log('fullYear', fullYear); //2018 Formatting function: moment.utc(new Date(month + ' ' + day +

How to translate a date object using angular-translate?

邮差的信 提交于 2020-01-02 03:42:23
问题 I have a list of date in my view, powered by my controller. I am using angular-translate to manage localisation in my all application but do not know how to deal with date object. My HTML looks like this : <div ng-repeat="date in nextDates"> <div class="day">{{date | date: 'EEEE'}}</div> </div> This code display a list a day : Monday, Tuesday, ... based on date which is a date object. My first try was to use moment.js which is already used in this project, and deal really well with i18n. It

moment.js, timezones and daylight savings

北战南征 提交于 2020-01-02 02:01:35
问题 I return a list of UTC dates/times from a .Net service, formatted like so: "2013-07-09 19:48:07 +00:00". On the client, I convert each of these string values into a corresponding UTC-based moment, like so var fooUtc = new moment.utc(serverDateTimeString) On the page, there is a droop-down containing a list of time-zones that the user can change. These are tied to a collection of time-zone objects like the following: { id: "Central Standard Time", label: "(UTC-06:00) Central Time (US & Canada)

moment.js, timezones and daylight savings

南楼画角 提交于 2020-01-02 02:00:05
问题 I return a list of UTC dates/times from a .Net service, formatted like so: "2013-07-09 19:48:07 +00:00". On the client, I convert each of these string values into a corresponding UTC-based moment, like so var fooUtc = new moment.utc(serverDateTimeString) On the page, there is a droop-down containing a list of time-zones that the user can change. These are tied to a collection of time-zone objects like the following: { id: "Central Standard Time", label: "(UTC-06:00) Central Time (US & Canada)