trx
trx

Reputation: 2157

Convert the DateTime in to Local time

I am pretty new to AngularJS. I am capturing a Datetime attribute in the UI and need to send it to the Odata end point. The time sent is not the current local time. How can I convert the time in to Local time before sending it to the Odata

<div>
    <label style="font-size: medium">Collection Time</label>
    <div name="collectionTime" uib-timepicker ng-model="sample.collectionTime"
         hour-step="hstep" minute-step="mstep" show-meridian="ismeridian" required>
    </div>
</div>

The Controller

var data = {
    "JAX_SAMPLELOT_TIMECOLLECTED": sample.collectionTime
}

enter image description here

Upvotes: 1

Views: 68

Answers (2)

Umut
Umut

Reputation: 37

  1. sample.collectionTime.toLocaleString() gives you 7/23/2019, 7:05:07 PM
  2. sample.collectionTime.toLocaleDateString () gives you 7/23/2019
  3. sample.collectionTime.toLocaleTimeString() gives you 7:04:57 PM

Check out https://www.w3schools.com/jsref/jsref_obj_date.asp for further Javascript Date object.

Upvotes: 0

mruanova
mruanova

Reputation: 7095

Here we use https://momentjs.com/ in some project and https://github.com/date-fns/date-fns in some other projects, they are both good options to convert time.

Upvotes: 1

Related Questions