简体   繁体   中英

Datetimepicker returns the date as a datetime format instead of timestamp

I'm using the datetimepicker js script and have the following logic implemented:

<script>
            var today = new Date();
            var dd = today.getDate();
            var mm = today.getMonth();
            var yy = today.getFullYear();
            var hh = today.getHours();
            var now = new Date();
            now.setHours(now.getHours() + 2);
            var isPM = now.getHours() >= 12;
            var isMidday = now.getHours() == 12;
            var result = document.querySelector('#result');
            var time = [now.getHours() - (isPM && !isMidday ? 12 : 0),
                now.getMinutes()].join(':') +
                    (isPM ? ' pm' : 'am');

            var logic = function (currentDateTime) {
                if (currentDateTime.getDate() == dd && currentDateTime.getFullYear() == yy && currentDateTime.getMonth() == mm) {

                    this.setOptions({
                        formatTime: 'g:i A',
                        format: 'd/m/Y h:i A',
                        minDate: '+1970/01/02', //or 1986/12/08,
                        minTime: time
                    });
                } else
                    this.setOptions({
                        formatTime: 'g:i A',
                        format: 'd/m/Y h:i A',
                        minDate: '+1970/01/02', //or 1986/12/08,
                        minTime: '0:00 AM'
                    });
            };


            jQuery('#datetimepicker').datetimepicker({
                onChangeDateTime: logic,
                onShow: logic
            });

        </script>

and now my dateTimepicker looks like this http://i.imgur.com/Cx3nXRo.png .

But when I choose some date and time later on (using var date = $("#datetimepicker").val(); ) in return I have the format 30/06/2015 02:04 PM , but I would like to have a timestamp instead. How can I convert it to the timestamp then?

Well you can try this:

jQuery('#datetimepicker').datetimepicker("getDate").getTime()/1000

This should return it in your desired time format.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM