How to create Moment based on given values

Is there any possiblity to create Moment object instance that represents local date/time based on given values?
I mean: user provides (via picker) values for year, month, day, hour, minutes, and I want to create Moment from these data.
I found (undocumented) function Gregorian.momentNative, that does exactly that, but it looks like it creates UTC time.

For example: here in middle Europe in Summer, if I call momentNative(2016, 9, 19, 0, 0, 0), it will create Moment with UTC time 00:00,
but in local time it is in fact 2:00 AM. So Gregorian.info() will return 2016-09-19 02:00.
I tried to calculate offset comparing Gregorian.info() with Gregorian.utcInfo(), but it got too complicated...
  • You should be able to do this given Gregorian.moment(), and if necessary the time zone offset specified in Sys.ClockTime. I don't have access to a working build environment at the moment to test this, but I believe this will create a moment for the given local time. We'll check in a second...

    var moment = Gregorian.moment({
    :year => 2016,
    :month => 9,
    :day_of_month => 19,
    :hour => 1,
    :min => 2,
    :sec => 3
    });


    When you extract the components with Gregorian.info() it will have the local time zone offset applied

    var info = Gregorian.info(moment, Time.FORMAT_SHORT);
    Sys.println(Lang.format("$1$-$2$-$3 $4$:$5$:$6$", [
    info.year,
    info.month.format("%02d"),
    info.day.format("%02d"),
    info.hour.format("%02d"),
    info.min.format("%02d"),
    info.sec.format("%02d")
    ]));


    If this prints 2016-09-19 01:02:03 then Gregorian.moment() expects the input date to be in local time, and we're done. If this prints something else, then Gregorian.moment() expects the input date to be in UTC time, and you must apply an offset to get from local to UTC before the Gregorian.info() call.

    moment = moment.add(new Time.Duration(-Sys.getClockTime().timeZoneOffset));


    You may have to play with the sign of the offset value. I can't remember if it is positive for time zones West of UTC or not.