https://github.com/bolorundurowb/moment.net
Basically as much of a dot net port of moment.js as necessary
https://github.com/bolorundurowb/moment.net
csharp dotnetcore moment netstandard
Last synced: 7 months ago
JSON representation
Basically as much of a dot net port of moment.js as necessary
- Host: GitHub
- URL: https://github.com/bolorundurowb/moment.net
- Owner: bolorundurowb
- License: mit
- Created: 2019-02-20T13:17:50.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2025-02-08T23:34:48.000Z (9 months ago)
- Last Synced: 2025-03-25T18:54:03.929Z (7 months ago)
- Topics: csharp, dotnetcore, moment, netstandard
- Language: C#
- Homepage:
- Size: 150 KB
- Stars: 21
- Watchers: 3
- Forks: 8
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# Moment.net β°
[](https://app.travis-ci.com/bolorundurowb/moment.net) [](https://coveralls.io/github/bolorundurowb/moment.net) [](LICENSE) 
## Overview π
This library aims to port as many bits of functionality from moment.js as necessary. Currently supported features include:
`FromNow`, `From`, `ToNow`, `To`, `StartOf`, `EndOf`, and `CalendarTime`. Additional functionalities not present in moment.js are also being added.
## Getting Started π
Install Moment.net via NuGet:
### Package Manager π¦
```
PM > Install-Package moment.net
```
### .NET CLI π»
```
> dotnet add package moment.net
```
### PackageReference π
```csharp
```
## Example Usage π οΈ
### FromNow β³
```csharp
var dateTime = new DateTime(2017, 1, 1);
var relativeTime = dateTime.FromNow(); // 2 years ago
```
### From βͺ
```csharp
var past = new DateTime(2017, 1, 1);
var future = new DateTime(2020, 1, 1);
var relativeTime = past.From(future); // 3 years ago
```
### ToNow β©
```csharp
var dateTime = new DateTime(2020, 1, 1);
var relativeTime = dateTime.ToNow(); // in one year
```
### To π―
```csharp
var past = new DateTime(2019, 1, 1);
var future = new DateTime(2021, 1, 1);
var relativeTime = past.To(future); // in 2 years
```
### StartOf π
```csharp
var date = DateTime.Parse("5/1/2008 8:30:52 AM", System.Globalization.CultureInfo.InvariantCulture);
var startOfDay = date.StartOf(DateTimeAnchor.Day); // 01/05/2008 00:00:00
```
### EndOf π
```csharp
var date = DateTime.Parse("5/1/2008 8:30:52 AM", System.Globalization.CultureInfo.InvariantCulture);
var endOfDay = date.EndOf(DateTimeAnchor.Day); // 01/05/2008 23:59:59
```
### CalendarTime π
```csharp
var startDateTime = new DateTime(2012, 12, 12);
var sameDay = new DateTime(2012, 12, 12, 12, 0, 0);
var calendarTime = startDateTime.CalendarTime(sameDay); // Today at 12:00 PM
```
### UnixTime β
```csharp
var dateTime = new DateTime(1971, 01, 01, 0, 0, 0, DateTimeKind.Utc);
var millisecondsElapsed = dateTime.UnixTimestampInMilliseconds(); // 31536000000
```
### First and Last Date in a Week π
```csharp
date.FirstDateInWeek(); // 27/04/2008 00:00:00 (previous month)
date.LastDateInWeek(); // 03/05/2008 00:00:00
```
### Next π
```csharp
var date = DateTime.Parse("5/1/2008 8:30:52 AM", System.Globalization.CultureInfo.InvariantCulture);
date.Next(DayOfWeek.Thursday); // 08/05/2008 08:30:52
```
### Last π
```csharp
var date = DateTime.Parse("5/1/2008 8:30:52 AM", System.Globalization.CultureInfo.InvariantCulture);
date.Last(DayOfWeek.Friday); // 25/04/2008 08:30:52
```
### Final π
```csharp
var date = DateTime.Parse("5/1/2008 8:30:52 AM", System.Globalization.CultureInfo.InvariantCulture);
date.Final().Monday().InMonth(); // 26/05/2008 00:00:00
```
### Format ποΈ
```csharp
var dateTime = new DateTime(1971, 01, 01, 0, 0, 0, DateTimeKind.Utc);
date.Format("yyyy MMM dd"); // 1971 Jan 01
```
### IsLeapYear π
```csharp
var dateTime = DateTime.Parse("1992-02-01");
dateTime.IsLeapYear(); // True
```
### Localization π
```csharp
var dateTime = new DateTime(2017, 1, 1);
var relativeTime = dateTime.FromNow(new CultureInfo("es")); // 6 aΓ±os atrΓ‘s
```
### Contributing π€
Want to add more languages? Simply create a `String.[language identifier].resx` file and follow the `Strings.es.resx` example.
## License π
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.