Showing the current system time


(Pleasecall911kenneth) #1

Hi! How do I show my current system (PC) time on a form

Right now I’m currently using a datetimepicker, I wanna try when I’m going to create something in a form the “time_start” will automatically get the time that is being used on my PC.


<?= $form->field($model, 'time_start')->widget(

                                DateTimePicker::className(), [

                                'options' => ['placeholder' => 'Render Time'],

                                'pluginOptions' => ['autoclose' => true,]

                                ]

    ); ?>



For example a basic PHP time function like this


<?php

$t=time();

echo($t . "<br>");

echo(date("Y-m-d",$t));

?>


(Alexander Makarov) #2

Use JavaScript.


(Pleasecall911kenneth) #3

I tried creating a script in javascript also did some research


<script>

	var currentTime = new Date(),

      hours = currentTime.getHours(),

      minutes = currentTime.getMinutes();


	if (minutes < 10) {

	 minutes = "0" + minutes;

      

      

  }

	document.write(hours + ":" + minutes)

    var currentDate = new Date(),

      day = currentDate.getDate(),

      month = currentDate.getMonth() + 1,

      year = currentDate.getFullYear();

  document.write(day + "/" + month + "/" + year)

</script>

As of now I have done this, I only have basic knowledge in javascript how do I merge it with a php form?