In C++, what's the easiest way to get the system time?

jamieyello

Professional Dumbass
OP
Member
Joined
Mar 11, 2013
Messages
385
Trophies
0
XP
546
Country
United States
I am writing a SmileBASIC interpreter, SmileBASIC being a modified version of basic that ran on the official licensed games Petit Computer (DSi) and SmileBASIC (3ds). I need a way to get time in order to recreate the WAIT (number) function, which takes in a number and stops for that amount of time in 1/60ths seconds. It doesn't actually wait, though, it throttles more like, so I need a way to measure when 1/60th of a second has passed, and not add the time it took to execute other running code to that.

I did this with <chrono>, but every time I make a specific completely unrelated string array larger than a couple of strings it returns a constant -2 million something, it's just not working correctly. Is there a good alternative, or does anyone know why it's acting this way?

Code:
...
#include <chrono>
...

//Outside my main loop
auto SBStartTime = Clock::now();

//This function returns how long the program has been running in 1/60ths of seconds
long long int getTime(){
     auto t2 = Clock::now();
     return std::chrono::duration_cast<std::chrono::nanoseconds>(t2-SBStartTime).count() / 16666666.6667;
}
 
Last edited by jamieyello,

jamieyello

Professional Dumbass
OP
Member
Joined
Mar 11, 2013
Messages
385
Trophies
0
XP
546
Country
United States
Last edited by jamieyello,

jamieyello

Professional Dumbass
OP
Member
Joined
Mar 11, 2013
Messages
385
Trophies
0
XP
546
Country
United States
I basically fixed this by moving the place where I declared the starting time (
autoSBStartTime=Clock::now();) to after all other arrays were set. I think they were conflicting somehow. Weird.

Edit Hey my code got a winky face
 
General chit-chat
Help Users
  • Sonic Angel Knight @ Sonic Angel Knight:
    Pork Provolone :P
  • Psionic Roshambo @ Psionic Roshambo:
    Sounds yummy
  • K3N1 @ K3N1:
    Sweet found my Wii u PSU right after I ordered a new one :tpi:
  • JuanMena @ JuanMena:
    It was waiting for you to order another one.
    Seems like, your PSU was waiting for a partner.
  • JuanMena @ JuanMena:
    Keep them both
    separated or you'll have more PSUs each year.
  • K3N1 @ K3N1:
    Well one you insert one PSU into the other one you get power
  • JuanMena @ JuanMena:
    It literally turns it on.
  • K3N1 @ K3N1:
    Yeah power supplies are filthy perverts
  • K3N1 @ K3N1:
    @Psionic Roshambo has a new friend
    +1
  • JuanMena @ JuanMena:
    It's Kyle, the guy that went to school to be a Certified man Kisser.
  • Psionic Roshambo @ Psionic Roshambo:
    Cartmans hand has taco flavored kisses
  • A @ abraarukuk:
    hi guys
  • Iron_Masuku @ Iron_Masuku:
    Hello
  • Vetusomaru @ Vetusomaru:
    @SylverReZ find me ONE community that is free of drama and politics. even video games forums (like this one) have politics section. and for some reason gamers still take consoles/brands wars seriously. even as a kid i never took the console wars bait despite being a nintendo kid.
  • Vetusomaru @ Vetusomaru:
    one of the reasons i deleted all my social media accounts, reddit account (although i was rarely using it) etc was to get away from this shit.
  • SylverReZ @ SylverReZ:
    @Vetusomaru, Sadly, not all communities like to play nice. Forums are pretty much dying despite Discord amongst other social media being available.
  • Vetusomaru @ Vetusomaru:
    i only kept my twitter accounts and only because many of the artists i like share their art only/mostly at twitter.
  • Vetusomaru @ Vetusomaru:
    lots of discord groups (even the big ones) are also dead for some reason.
  • SylverReZ @ SylverReZ:
    Twitter is way too shittier.
  • Vetusomaru @ Vetusomaru:
    that's why i added some firefox addons to block shit like twitter trends.
  • SylverReZ @ SylverReZ:
    Discord, on the other hand, moderation tends to not be very nice in video game communities from what I had experienced.
  • Vetusomaru @ Vetusomaru:
    nah, discord is also a shithole. discord is good only if you have your own community with your own rules. or if you re lucky to find some groups that arent shitholes.
  • Vetusomaru @ Vetusomaru:
    as about forums, when i recently revisited some old forums i used to be regular and seeing how immature most members still are i was like "Yeap. Nothing of value has been lost.". Unfortunately it's the good, comfy forums that ended up dead or shut down, especially because of internet centralization.
    Vetusomaru @ Vetusomaru: as about forums, when i recently revisited some old forums i used to be regular and seeing how...