Home > Back-end >  How to convert tick into DD/MM/YYYY format where one tick = 1 day
How to convert tick into DD/MM/YYYY format where one tick = 1 day

Time:09-30

I would like to convert the tick integer into a DD/MM/YYYY format where each tick is equal to 1 day. For example it starts at 1/1/1500 and the next tick it changes to 2/1/1500. I don't want hours, minutes, seconds I just want the date format. Sorry if something similar has been posted I tried using datetime but I don't think that's what I'm looking for. Unless i was just to set 1 tick equal to however many seconds a full day is.

This is what I've got for the tick system. Instead of displaying the number of ticks I would like to display the date.

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class TimeTickSystem : MonoBehaviour
{
public class OnTickEventArgs : EventArgs
{
    public int tick;
}

public static event EventHandler<OnTickEventArgs> OnTick;

public GameObject textDisplay;

private const float Tick_Timer_Max = 0.2f;

private int tick;
private float tickTimer;

private void Awake()
{
    tick = 0;
}

private void Update()
{

    tickTimer  = Time.deltaTime;
    if (tickTimer >= Tick_Timer_Max)
    {
        tickTimer -= Tick_Timer_Max;
        tick  ;
        if (OnTick != null) OnTick(this, new OnTickEventArgs { tick = tick });
        textDisplay.GetComponent<Text>().text = "Tick: "   tick;
    }
}

}

CodePudding user response:

You should be able to just create an instance of DateTime at 1500/1/1:

DateTime startDate = new DateTime(1500, 1, 1);

And then add the number of days you want to it:

DateTime tickDate = startDate.AddDays(tick);

Or simply:

DateTime tickDate = new DateTime(1500, 1, 1).AddDays(tick);
  • Related