Re: Get milliseconds from time and construct time based on milliseconds

2024-05-28 Thread Steven Schveighoffer via Digitalmars-d-learn

On Tuesday, 28 May 2024 at 18:41:02 UTC, bauss wrote:

On Tuesday, 28 May 2024 at 18:29:17 UTC, Ferhat Kurtulmuş wrote:

On Tuesday, 28 May 2024 at 17:37:42 UTC, bauss wrote:
I have two questions that I can't seem to find a solution to 
after looking at std.datetime.


First question is how do I get the current time but in 
milliseconds?


Second is how do I construct a time ex. systime or datetime 
based on milliseconds?


Thanks


Unixtime might be what you want:

import std;

import std.datetime;
import std.stdio;

void main() {
// Get the current time in the UTC time zone
    auto currentTime = Clock.currTime();

// Convert the time to the Unix epoch 
(1970-01-01T00:00:00Z)
    Duration unixTime = currentTime - 
SysTime(DateTime(1970, 1, 1), UTC());


You can do `SysTime(unixTimeToStdTime(0))` to get a SysTime that 
is at the unix epoch.




Also figured out the second question based on your result.

Simply doing:

```
SysTime(DateTime(1970, 1, 1), UTC()) + dur!"msecs"(milliseconds)
```

Seems to work.


Note there is an `msecs` function:

```d
SysTime(unixTimeToStdTime(0)) + milliseconds.msecs;
```

https://dlang.org/phobos/std_datetime_systime.html#unixTimeToStdTime
https://dlang.org/phobos/core_time.html#msecs

-Steve


Re: Get milliseconds from time and construct time based on milliseconds

2024-05-28 Thread bauss via Digitalmars-d-learn

On Tuesday, 28 May 2024 at 18:29:17 UTC, Ferhat Kurtulmuş wrote:

On Tuesday, 28 May 2024 at 17:37:42 UTC, bauss wrote:
I have two questions that I can't seem to find a solution to 
after looking at std.datetime.


First question is how do I get the current time but in 
milliseconds?


Second is how do I construct a time ex. systime or datetime 
based on milliseconds?


Thanks


Unixtime might be what you want:

import std;

import std.datetime;
import std.stdio;

void main() {
// Get the current time in the UTC time zone
    auto currentTime = Clock.currTime();

// Convert the time to the Unix epoch 
(1970-01-01T00:00:00Z)
    Duration unixTime = currentTime - 
SysTime(DateTime(1970, 1, 1), UTC());


// Get the total milliseconds
long milliseconds = unixTime.total!"msecs";

// Print the Unix time in milliseconds
writeln("Unix time in milliseconds: ", milliseconds);
}


Thanks a lot.

Also figured out the second question based on your result.

Simply doing:

```
SysTime(DateTime(1970, 1, 1), UTC()) + dur!"msecs"(milliseconds)
```

Seems to work.


Re: Get milliseconds from time and construct time based on milliseconds

2024-05-28 Thread Ferhat Kurtulmuş via Digitalmars-d-learn

On Tuesday, 28 May 2024 at 17:37:42 UTC, bauss wrote:
I have two questions that I can't seem to find a solution to 
after looking at std.datetime.


First question is how do I get the current time but in 
milliseconds?


Second is how do I construct a time ex. systime or datetime 
based on milliseconds?


Thanks


Unixtime might be what you want:

import std;

import std.datetime;
import std.stdio;

void main() {
// Get the current time in the UTC time zone
    auto currentTime = Clock.currTime();

// Convert the time to the Unix epoch 
(1970-01-01T00:00:00Z)
    Duration unixTime = currentTime - SysTime(DateTime(1970, 
1, 1), UTC());


// Get the total milliseconds
long milliseconds = unixTime.total!"msecs";

// Print the Unix time in milliseconds
writeln("Unix time in milliseconds: ", milliseconds);
}



Get milliseconds from time and construct time based on milliseconds

2024-05-28 Thread bauss via Digitalmars-d-learn
I have two questions that I can't seem to find a solution to 
after looking at std.datetime.


First question is how do I get the current time but in 
milliseconds?


Second is how do I construct a time ex. systime or datetime based 
on milliseconds?


Thanks


Re: Hide console on Windows with app running SDL2

2024-05-28 Thread bauss via Digitalmars-d-learn
On Tuesday, 28 May 2024 at 12:45:39 UTC, Steven Schveighoffer 
wrote:

On Tuesday, 28 May 2024 at 12:35:42 UTC, bauss wrote:
Running into a couple of problems trying to hide the console 
that opens when running an app that uses sdl2.


First of all I am trying to compile with this using dub:

```
"lflags": ["/SUBSYSTEM:windows"]
```

However that gives me the following error:

```
error LNK2019: unresolved external symbol WinMain
```

And then if I add a WinMain like below:

```
extern (Windows) int WinMain() { return 0; }
```

Then of course it doesn't work, but what is the obvious way to 
solve this?


I basically just want to hide the console, but nothing seems 
to work straight out of the box.


I think this is still relevant: 
https://wiki.dlang.org/D_for_Win32


-Steve


Thanks a lot, that helped and solved the issue


Re: Hide console on Windows with app running SDL2

2024-05-28 Thread Steven Schveighoffer via Digitalmars-d-learn

On Tuesday, 28 May 2024 at 12:35:42 UTC, bauss wrote:
Running into a couple of problems trying to hide the console 
that opens when running an app that uses sdl2.


First of all I am trying to compile with this using dub:

```
"lflags": ["/SUBSYSTEM:windows"]
```

However that gives me the following error:

```
error LNK2019: unresolved external symbol WinMain
```

And then if I add a WinMain like below:

```
extern (Windows) int WinMain() { return 0; }
```

Then of course it doesn't work, but what is the obvious way to 
solve this?


I basically just want to hide the console, but nothing seems to 
work straight out of the box.


I think this is still relevant: https://wiki.dlang.org/D_for_Win32

-Steve