Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Implemented Datetime object support #675

Closed
wants to merge 12 commits into from
51 changes: 51 additions & 0 deletions docs/docs/standard-lib/datetime.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,37 @@ import Datetime;
| Datetime.SECONDS_IN_DAY | The number of seconds in a day. |
| Datetime.SECONDS_IN_WEEK | The number of seconds in a week. |


### Datetime.new() -> Datetime

Returns a datetime object with current datetime.

```cs
var datetime = Datetime.new();
datetime.toString(); // Fri May 29 03:12:32 2020
```

### Datetime.new(String, String) -> Datetime

Returns a datetime object for given time string format.

**Note:** This is not available on windows systems.

```cs
var datetime = Datetime.new("%Y-%m-%d %H:%M:%S", "2020-01-01 00:00:00");
datetime.toString(); // Wed Jan 1 00:00:00 2020
```

### Datetime.new(Number) -> Datetime

Returns a datetime object for given number of seconds from epoch.

```cs
const datetime = Datetime.new(1577836800);
datetime.toString(); // Wed Jan 1 00:00:00 2020
```


### Datetime.now() -> String

Returns a human readable locale datetime string.
Expand Down Expand Up @@ -107,3 +138,23 @@ the date string in the format of the first parameter.
Datetime.strptime("%Y-%m-%d %H:%M:%S", "2020-01-01 00:00:00"); // 1577836800
```

### datetimeObj.strptime() -> Number

Returns a number which is the number of seconds from epoch, for a given datetime

**Note:** This is not available on windows systems.

```cs
const datetime = Datetime.new("%Y-%m-%d %H:%M:%S", "2020-01-01 00:00:00");
datetime.strptime(); // 1577836800
```

### datetimeObj.strftime(String) -> String

Returns a user-defined datetime formatted string for a datetime object, see [Datetime formats](#datetime-formats).

```cs
const datetime = Datetime.new();
datetime.strftime("Today is %A"); // Today is Friday
```

Loading