Create a Date with a set timezone without using a string representation

前端 未结 23 1445
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-11-22 01:48

I have a web page with three dropdowns for day, month and year. If I use the JavaScript Date constructor that takes numbers, then I get a Date obje

23条回答
  •  南方客
    南方客 (楼主)
    2020-11-22 02:03

    d = new Date();
    utc = d.getTime() + (d.getTimezoneOffset() * 60000);
    nd = new Date(utc + (3600000*offset));
    
    offset value base on which location time zone you would like to set 
    For India offset value +5.5,
    New York offset value -4,
    London offset value +1
    

    for all location offset Wiki List of UTC time offsets

提交回复
热议问题