简体   繁体   中英

Get Today date using Jquery Full Calender

I am using Jquery "Fullcalender.js" file version (FullCalendar v2.2.5)
I have one dive in may .aspx page

<div id="jweek"></div>

In this div i want to display today's date in format

2020-02-08 00:00:00.000

Here is my jquery code

 <script type="text/javascript">
       $(document).ready(function () {
           $('#jweek').fullCalendar('today');
        });    
    </script>

Code for Dynamic Checkbox list

<script>

    $(document).ready(function () {

        var checkedvalue = [];
         $.ajax({

            type: "POST",

            url: "WebForm1.aspx/GetRole",

            data: '',
            //data: JSON.stringify(obj),

            contentType: "application/json; charset=utf-8",

            dataType: "json",

            success: function (data) {

                var json = JSON.parse(data.d);

                var val = 0;

                var table = $('<table></table>');

                var option = json.map(x =>

                    table.append($('<tr></tr>').append($('<td></td>').append($('<input>').attr({

                        type: 'checkbox', name: 'chkRoles', value: x.chkName, id: 'chkrole' + val

                    }))).append(

                        $('<label>').attr({

                            for: 'chkRoles' + val++

                        }).text(x.chkName))));



                $('#chkrole').append(table);

            }

        });

        $("#btnget").click(function () {

            checkedvalue = [];

            $("input[name=chkRoles]").each(function () {

                if ($(this).is(":checked")) {

                    checkedvalue.push($(this).val());

                }

            });

            $("#lblSelected").text(checkedvalue);

        });


    });

</script>

So as you can see in above dynamic checkbox list i want to pass the current date of calender and based on that i want to generate checkbox list for next 7 days. I hope my question is clear and sorry for my english
Here is my web method in which i want to pass current calender date so can go though loop

 [WebMethod()]
// Get current select date from calender and generate next 7 days inside the //checkbox
        public static string GetRole()
         {
//Use the date which is passed
            DateTime today = '';
            DataTable dt = new DataTable();

            dt.Columns.Add("Id", typeof(int));

            dt.Columns.Add("chkName", typeof(string));

            for (int i = 1; i <= 7; i++)
            {

            }

            return JsonConvert.SerializeObject(dt);

        }

You can Get the today date with simple javascript code below :-

 var d = new Date();
var month = d.getMonth()+1;
var day = d.getDate();
var output = d.getFullYear() + '/' +    ((''+month).length<2 ? '0' : '') + month + '/' +    ((''+day).length<2 ? '0' : '') + day;
alert(output);

Currently I stored the current date value in "Output" variable. you can put the value as per your requirement.

var custom_format= $('#YourCalendar').fullCalendar('getDate');
var calDate = custom_format.format('DD.MM.YYYY HH:mm'); //Here you can format your Date

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