momentjs

Momentjs : How to prevent “Invalid date”?

别来无恙 提交于 2021-02-06 15:00:14
问题 I have the following code : var fomattedDate = moment(myDate).format("L"); Sometimes moment(myDate).format("L") returns "Invalid date", I want to know if there is a way to prevent that and return an empty string instead. 回答1: TL;DR If your goal is to find out whether you have a valid date, use Moment's isValid : var end_date_moment, end_date; jsonNC.end_date = jsonNC.end_date.replace(" ", "T"); end_date_moment = moment(jsonNC.end_date); end_date = end_date_moment.isValid() ? end_date_moment

How to get difference between times in decimal in moment js?

天大地大妈咪最大 提交于 2021-02-05 10:55:17
问题 How to get the difference between times in decimal in moment js? For example: in: '17:39', out: '21:10'. I try to do this code but it's not work for me: let startTime = project[0].in; let end = project[0].out; startTime = moment(startTime, ['H:m']); end = moment(end, ['H:m']); var duration = moment.duration(end.diff(startTime)); var hours = duration.asHours(); var minutes = parseInt(duration.asMinutes()) % 60; console.log({ hours, minutes }); const a = duration.asMinutes(); //moment.duration(

How to get difference between times in decimal in moment js?

假装没事ソ 提交于 2021-02-05 10:55:13
问题 How to get the difference between times in decimal in moment js? For example: in: '17:39', out: '21:10'. I try to do this code but it's not work for me: let startTime = project[0].in; let end = project[0].out; startTime = moment(startTime, ['H:m']); end = moment(end, ['H:m']); var duration = moment.duration(end.diff(startTime)); var hours = duration.asHours(); var minutes = parseInt(duration.asMinutes()) % 60; console.log({ hours, minutes }); const a = duration.asMinutes(); //moment.duration(

How to convert dates to UNIX timestamps in MomentJS?

半城伤御伤魂 提交于 2021-02-05 07:52:06
问题 I want to convert my date time values to Unix timestamp format (basically an epoch timestamp). For that I use: let startDate = '2018-09-28 11:20:55'; let endDate = '2018-10-28 11:20:55'; let test1 = startDate.unix(); let test2 = endDate.unix(); However it gives me an error ERROR TypeError: Cannot read property 'Unix' of undefined Can anyone tell me how I can convert datetime to Unix using MomentJS? 回答1: The issue is because you're calling unix() on plain strings. You need to instead call it

Moment format returns invalid date

大城市里の小女人 提交于 2021-02-04 12:21:48
问题 i have a date which i formated using moment to be shown like this: 03/04/2105. I want to transform it to iso using moment again. As a result i'm writing: const IsoDateTo = moment(dateTo).format('YYYY-MM-DD[T]HH:mm:ss'); The date to is 23/04/2105 but the IsoDateTo is returning something like this: 2105-03-04T00:00:00 Also when i enter a date greater than 12 it returns me Invalid Date. Why is this happening? 回答1: To make sure that you are correctly parsing the string you want to pass the

Formatting momentjs date-time

这一生的挚爱 提交于 2021-01-29 16:57:19
问题 Hi everyone I have looked at a few SO questions but have yet to find a solid answer to my problem. Question I have already looked at include: Moment.js returning wrong date Moment JS - parse UTC and convert to Local and vice versa My question is the following: I have a basic time selector with times ranging from 4:00am - 8:00pm. I want to use the time selected along with a hard-coded date to format something that looks like this: "2015-05-03T04:00:00" Here's what I have so far: time = moment(

How to use the moment library in React Bootstrap table's column definition?

拥有回忆 提交于 2021-01-29 10:24:26
问题 My code looks as following: const columns = [{ dataField: 'Id', text: 'Order ID' }, { dataField: 'Date', text: 'Date' }, { dataField: 'Total', text: 'Total' }]; And it displays date in React Bootstrap table. But, the date is in Json format that I don't need. I've tried to use the moment library to format date in this way: const columns = [{ dataField: 'Id', text: 'Order ID' }, { dataField: '{moment(Date).format("DD-MM-YYYY")}', text: 'Date' }, { dataField: 'Total', text: 'Total' }]; But, the

Datatables and Moment.js for D-MMM-YY sorting

蓝咒 提交于 2021-01-29 08:31:52
问题 I'm trying to get my datatables with dates entered in the D-MMM-YY format to be sorted but it doesn't appear to do so, only by the 1st digit in the date. For example, it sorts 9-Sep-13 before 1-Jun-20. A typical table line is as follows: <tr> <td>25-Jul-11</td> <td>Announcement</td> <td><a href="#">#</a></td> </tr> My javascript is as follows: <script type="text/javascript"> $(document).ready(function() { $.fn.dataTable.moment( 'D-MMM-YY'); $('#pn2020').DataTable({ "pageLength": 20, order: [[

Convert string to date using moment.js [duplicate]

一世执手 提交于 2021-01-29 06:45:28
问题 This question already has answers here : Moment.js - how do I build moment from date and time string? (2 answers) Closed 3 years ago . This my model.ts export class Feature2 { requestRouteTemplate: string; requestMethod: string; numberCount: number; requestDate: date; constructor(values: Object = {}) { Object.assign(this, values); } } This is component.ts this.datas2 = [ { 'requestRouteTemplate': 'api/Tasks', 'requestMethod': 'POST', 'numberCount': 6, 'requestDate': '07/01/2017', }, {

Telegram bot api not able to restrict user for 24 hours

你离开我真会死。 提交于 2021-01-29 05:58:39
问题 Looking for solution to restrict chat member with restrictChatMember() but unfortunately it still restrict the user forever not for 24 hours. const { date:joinDate } = ctx.message; const releaseDate = moment.unix(joinDate).add(1, 'day'); ctx.telegram.restrictChatMember( ctx.chat.id, memberID, releaseDate, false, false, false, false ); Reference: https://core.telegram.org/bots/api#restrictchatmember 回答1: You're passing a moment object back into the function, not an UNIX timestamp like the docs