0

The server returns me the date of example 2019-07-30, 23:59 I put it in the selected property, 23:59 is displayed in input. I live in Poland. How to change to display 23:00? I use this library: https://www.npmjs.com/package/react-datepicker

  

 <DatePicker
      selected = {} 
      onChange this.props.handleChangeDateTask = {}
      showTimeSelect
      timeformat = "HH: mm"
      timeIntervals = {15}
      dateFormat = "dd / MM / yyyy HH: mm"
      timeCaption = "time"
    />
Umbro
  • 1,984
  • 12
  • 40
  • 99

2 Answers2

0

Assuming you are getting utc time from the server,

you can use new Date('2019-07-30 23:59 UTC') (just append 'UTC' to your date) as the selected in <DatePicker/>,

if you are getting the time in another timezone you will have to use moment to convert it to your timezone

Anuja
  • 908
  • 6
  • 11
  • And if I kept date from server and it is assign to a variable `date`, how can I add UTC? – Umbro Sep 04 '19 at 12:16
  • are you creating a `javascript` `Date` object from the server date? if not i should be coming to you as a string right? If its a string you can just concatenate "UTC" to it manually. – Anuja Sep 04 '19 at 12:18
0

Assuming the server is sending utc time you can covert that to local time

var date = new Date('6/29/2011 4:52:48 PM UTC');
date.toString() // "Wed Jun 29 2011 09:52:48 GMT-0700 (PDT)"

Convert UTC date time to local date time

Use this logic to show correct local time.

indolentdeveloper
  • 1,253
  • 1
  • 11
  • 15