trentrichardson / jQuery-Timepicker-Addon

Adds a timepicker to jQueryUI Datepicker
http://trentrichardson.com/examples/timepicker/
MIT License
2.66k stars 1.05k forks source link

How to set date and time using Javascript? #473

Open sidchilling opened 11 years ago

sidchilling commented 11 years ago

How can I explicitly set the date, time and timezone in the datetime picker. I have a datetime string of the format '24-Oct-2012 Asia/Kolkata' and I want to display it in the datetime picker.

I have configured the datetimepicker with the following options -

dateFormat : 'dd-M-yy' timeFormat : 'hh:mm z' showTimezone : true timezoneText : 'TZ' timezoneList : myTimeZoneList

Where

myTimeZoneList = [ {'value' : 'America/Los_Angeles', 'label' : 'Pacific'}, {'value' : 'America/Denver', 'label' : 'Mountain'}, {'value' : 'America/Chicago', 'label' : 'Central'}, {'value' : 'America/New_York', 'label' : 'Eastern'}, {'value' : 'UTC', 'label' : 'GMT'}, {'value' : 'Asia/Kolkata', 'label' : 'Indian'} ]

So basically when my page is loaded, I get the value of the datetimepicker from the database and I want to populate my datetimepicker field with it properly. So far, I can't find how to do this?

trentrichardson commented 11 years ago

There is an option called "defaultTimezone" or you can populate the input with the formatted time.

sidchilling commented 11 years ago

How can I populate the input with formatting? Any example available ?

On Wed, Oct 10, 2012 at 12:47 AM, Trent Richardson <notifications@github.com

wrote:

There is an option called "defaultTimezone" or you can populate the input with the formatted time.

— Reply to this email directly or view it on GitHubhttps://github.com/trentrichardson/jQuery-Timepicker-Addon/issues/473#issuecomment-9275288.

Siddharth Saha Skype: siddharth.saha

trentrichardson commented 11 years ago

If your format is "hh:mm z" then when building your html just set the value:

You just have to be sure the value matches the format is all.

On Tue, Oct 9, 2012 at 3:21 PM, sidchilling notifications@github.comwrote:

How can I populate the input with formatting? Any example available ?

On Wed, Oct 10, 2012 at 12:47 AM, Trent Richardson < notifications@github.com

wrote:

There is an option called "defaultTimezone" or you can populate the input with the formatted time.

— Reply to this email directly or view it on GitHub< https://github.com/trentrichardson/jQuery-Timepicker-Addon/issues/473#issuecomment-9275288>.

Siddharth Saha Skype: siddharth.saha

— Reply to this email directly or view it on GitHubhttps://github.com/trentrichardson/jQuery-Timepicker-Addon/issues/473#issuecomment-9275425.

Thanks,

Trent Richardson

trentdrichardson@gmail.com

trentrichardson.com

sidchilling commented 11 years ago

I set the value in the HTML as "01-Oct-2012 21:31 America/Denver". The text is displaying properly in the input field. However, when I click on the input field to get the datetimepicker, the date and the time are set properly but the timezone selected from the timezone dropdown list is always America/Los_Angeles.