Sign In Register

How can we help you today?

Start a new topic
Solved

Date Parse in Snippet

I'm trying to create time based objects using the manage tab and admin screens.


To that end I have a form snippet with GSHTML:

         <gs-col width="3">

            <input type="date" name="start_date"/>

        </gs-col>

        <gs-col width="2">

            <input type="time" name="start_time"/>

        </gs-col>


I'm trying to parse the resulting values of start_date and start_time into a timestamp value to go into my datastore.

start_date might look like "2015-01-01" and start_time = "12:23"


I try things like:

 timestamp = Date.parse(start_date + " " start_time);

but that fails with timestamp = NaN;


I've also tried hard-coding the date string, (this hard-coded version works in chrome, and seems to follow the documentation)

 timestamp = Date.parse("2014-01-10 11:00")

but again, GameSparks is returning NaN


Anyone have an idea?


Hello Arnold V,


I think the easiest approach for you would be to use our custom datetimepicker:

<gs-col width="3">
    <input class="datetimepicker" name="start_date"/>
</gs-col>

<script>
    setTimeout(function(){
        $( ".datetimepicker" ).datetimepicker({
            dateFormat: "yy-mm-dd",
            separator:"T",
            timeFormat: "HH:mm"
        });
    }, 500);
</script>

 

Hope this helps,


Mantas

That helps, but doesn't get me all the way to where I need to be. I need to be able to get the UNIX timestamp out of the picker... is there documentation that helps with what widgets are available in Gamesparks? Is there documentation for the datetimepicker that is integrated?

Looks like this is what's being used: http://trentrichardson.com/examples/timepicker/


Figured out that the time format you used does work with the Date.parse() on the first snippet page, but I'm still not able to call Date.parse() successfully in the target snippet.

Hello there,


I would be also interested in creating a timestamp from the datepickers' outcome... the Date.parse() method does return "NaN", if applied on a string like "2015-12-31T23:00". (as far as I can see by outputting it to outcome console in the left bottom).


However, if I try it in the Javascript console of a browser (e.g. Chrome), it does give me a date...



ya,..i have same problem too...tried some ways..but didn't get timestamp...


var date = new Date('2016-01-07T02:00Z'); giving 0 as response

var date = Date.parse('2014-05-07T02:00Z'); giving "NaN" as response


var date = new Date('2016-01-07T02:00Z').toUTCString(); giving "Invalid Date" as response..


above statements are working fine when executed in console.....giving above responses when executed in snippet builder or cloudcode...


this is an old post but...


apparently the reason that the datetimepicker's output from   

<gs-col width="3">
    <input class="datetimepicker" name="start_date"/>
</gs-col>

<script>
    setTimeout(function(){
        $( ".datetimepicker" ).datetimepicker({
            dateFormat: "yy-mm-dd",
            separator:"T",
            timeFormat: "HH:mm"
        });
    }, 500);
</script>

doesn't work is due to a date string that cannot be parsed. according to ISO8601, the string should look something like this:


YYYY-MM-DDTHH:mm:ss.sssZ


but haven't close to zero html/jquery knowledge myself, i just cannot figure out how to add the "Z" at the end. so one way of doing it, if you really want the ISO format, is this:

<gs-col width="3">
    <input class="datetimepicker" name="start_date"/>
</gs-col>

<script>
    setTimeout(function(){
        $( ".datetimepicker" ).datetimepicker({
            dateFormat: "yy-mm-dd",
            separator:"T",
            timeFormat: "HH:mm:ss.sss"
        });
    }, 500);
</script>

 and when creating the date object: 

var dateObj = new Date(data.start_date + "Z");

 or just forget about the custom formatting and use the datetimepicker's default settings:

<gs-col width="3">
    <input class="datetimepicker" name="start_date"/>
</gs-col>

<script>
    setTimeout(function(){
        $( ".datetimepicker" ).datetimepicker();
    }, 500);
</script>

 which works out of the box...

Login to post a comment