Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

189
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda