unity get time code example

Example 1: python get date and time

import datetime
now = datetime.datetime.now()
print ("Current date and time : ")
print (now.strftime("%Y-%m-%d %H:%M:%S"))

Example 2: c# get time

//Return the time from DateTime object in string format
var timeString = DateTime.Now.ToString("hh:mm:ss");

//Return time in 24h format
var time24 = DateTime.Now.ToString("HH:mm:ss");
  
//Use short time format to return string value
var timeString = DateTime.Now.ToString("t");
var shortTimeStr = DateTime.Now.ToShortTimeString();

//Use long time format
var longTimeStr = DateTime.Now.ToLongTimeString();
var longtimestr = DateTime.Now.ToString("T");

//Return a TimeSpan from midnight
var timeSpan = DateTime.Now.TimeOfDay;

Example 3: unity system time

System.DateTime.Now

Example 4: c get time

/* localtime example */
#include <stdio.h>
#include <time.h>

int main ()
{
  time_t rawtime;
  struct tm * timeinfo;

  time ( &rawtime );
  timeinfo = localtime ( &rawtime );
  printf ( "Current local time and date: %s", asctime (timeinfo) );
  
  return 0;
}

Example 5: time.time unity

/*The time at the beginning of this frame (Read Only). This is the time in
  seconds since the start of the game.

  Time.time is the amount of time in seconds that the application has been
  running for. It is read-only.

  The application receives the current Time.time at the beginning of each frame,
  with the value increasing per frame. A time call per frame receives the same
  value. When called from FixedUpdate it returns the Time.fixedTime property.

  Regular (per frame) calls should be avoided: Time.time is intended to supply
  the length of time the application has been running for, and not the time per
  frame.

  The value of Time.time is undefined during Awake messages and will start after
*/all messages are finished.
//Ex.:

int time = Time.time; //the variable time has a value equals to the
//amount of time in seconds that the application has been
//running for.