Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

192
Vistas
C# WFA VS - speed up alternative in-game clock connected to local time DateTime.Now

so i've found some code, and applied to my needs, and it seems to work, but now i need to do the same stuff in C# (for and app) or to do an app for windows in javascript. any help? here's the code:

const speed = 7; // how many times faster than real time
    let clockDiv = document.querySelector("#clock");
    let gameStartTime = 10800000; // game-milliseconds;
    let realStartTime = Date.now(); // real milliseconds

    let timerId = setInterval(function() {
      let gameTime = gameStartTime + Date.now() * speed;
      let sec = Math.floor(gameTime / 1000) % 60;
      let min = Math.floor(gameTime / 60000) % 60;
      let hour = Math.floor(gameTime / 3600000) % 24;
      // output in hh:mm:ss format:
      clockDiv.textContent = `${hour}:${min}:${sec}`.replace(/\b\d\b/g, "0$&");
    }, 50);
<div id="clock" style="font-size:40pt;"></div>

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

C# Winform:

MainDesign:

Control required:

  1. Label*1
  2. Timer*1

enter image description here

Timer:

enter image description here enter image description here

Code:

using System;
using System.Windows.Forms;

namespace WindowsFormsApp3
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        public static long currentTimeMillis()
        {
            return (System.DateTime.UtcNow.Ticks - Jan1st1970Ms) / 10000;
        }
        private static long Jan1st1970Ms = new System.DateTime(1970, 1, 1, 0, 0, 0, System.DateTimeKind.Utc).Ticks;
        private void timer1_Tick(object sender, EventArgs e)
        {
            const int speed = 7;
            int gameStartTime = 10800000;
            Double realStartTime = currentTimeMillis();
            var gameTime = gameStartTime + realStartTime * speed;
            var sec = Math.Floor(gameTime / 1000) % 60;
            var min = Math.Floor(gameTime / 60000) % 60;
            var hour = Math.Floor(gameTime / 3600000) % 24;
            label1.Text = string.Format("{0:00}:{1:00}:{2:00}", hour, min, sec);
        }
    }
}

Output:

enter image description here

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda