0

I am using the owl-date-time module in my application to get date-time parameters in two fields. However, I am getting the value in a list with an additional null value in the payload. Also, I wish to convert the value to epoch time to meet the API requirements. In HTML Component:

<div class="form-group row">
  <label class="col-md-3 col-form-label text-right">
    Start Time
    <span class="colorRed">*</span>
  </label>
  <div class="col-lg-5 col-sm-11">
    <input type="text" id="start_time" style="height: 36px;"
     class="form-control" [selectMode]="'rangeFrom'" name="start_time"
     placeholder="Start Time" [(ngModel)]="startTime"
     [owlDateTimeTrigger]="dt1" [owlDateTime]="dt1"
     (change)="getTime(startTime,dt1)" [max]="maxFrom"
     autocomplete="off" required>
    <owl-date-time #dt1></owl-date-time>
  </div>
<!---->
</div>
    <div class="form-group row">
      <label class="col-md-3 col-form-label text-right">
       Stop Time
       <span class="colorRed">*</span>
      </label>
      <div class="col-lg-5 col-sm-11">
       <input type="text" id="stop_time" style="height: 36px;"
        class="form-control" [selectMode]="'rangeTo'" name="stop_time"
        placeholder="End Time" [(ngModel)]="stopTime"
        [owlDateTimeTrigger]="dt2" [owlDateTime]="dt2"
        (change)="getTime(stopTime,dt2)" [min]="minTo"
        autocomplete="off" required>
       <owl-date-time #dt2></owl-date-time>
      </div>
   </div>
</div>

In Typescript, I am calling this function to do the conversion. But I do not think that the function is getting called as I am unable to get any console logs. TS Code

      getTime(t, selectMode) {
        console.log("Hello Chuckles");
        let tempRangeFrom, tempRangeTo;
        t.forEach(element => {
          if (typeof (element) != 'undefined' && element != null) {
            if (element[1] != null) {
                console.log("FROM!@#$%^&*()");
              tempRangeFrom = element.getTime();  // Date To TimeStamp
              this.minTo = new Date(tempRangeFrom); // TimeStamp to Date
              this.minTo.toGMTString();
            } else {
              tempRangeTo = element.getTime();
              this.maxFrom = new Date(tempRangeTo);
              this.maxFrom.toGMTString();
            }
          }
        });
      }
  • Screenshot for date-picker:

DatePicker

  • Payload:

Payload

Anuj Kalra
  • 73
  • 1
  • 8

1 Answers1

1

You can simply do this:

const date = new Date()

console.log(new Date(date).getTime())

You can also check this link if the above code doesn't help.

Apoorva Chikara
  • 8,277
  • 3
  • 20
  • 35