![]() |
VOOZH | about |
dotnet add package WhatTimeIsIt --version 1.0.2
NuGet\Install-Package WhatTimeIsIt -Version 1.0.2
<PackageReference Include="WhatTimeIsIt" Version="1.0.2" />
<PackageVersion Include="WhatTimeIsIt" Version="1.0.2" />Directory.Packages.props
<PackageReference Include="WhatTimeIsIt" />Project file
paket add WhatTimeIsIt --version 1.0.2
#r "nuget: WhatTimeIsIt, 1.0.2"
#:package WhatTimeIsIt@1.0.2
#addin nuget:?package=WhatTimeIsIt&version=1.0.2Install as a Cake Addin
#tool nuget:?package=WhatTimeIsIt&version=1.0.2Install as a Cake Tool
<p align="center"> <img src="assets/logo.png" alt="WhatTimeIsIt Logo" width="192" height="192"> </p>
A comprehensive .NET library for parsing DateTime and DateTimeOffset strings from various database systems and standard formats while preserving microsecond precision and timezone offsets.
<sub>Logo by Uniconlabs</sub>
WhatTimeIsIt provides robust DateTime parsing that handles:
dotnet add reference path/to/WhatTimeIsIt.csproj
Or copy the WhatTimeIsIt project into your solution.
The simplest way to parse datetime strings:
using WhatTimeIsIt;
// Parse a datetime string using default formats
DateTime dt = DateTimeParser.ParseString("2024-01-15 14:30:45.123456");
Console.WriteLine(dt); // 1/15/2024 2:30:45 PM
// Safe parsing with TryParse
if (DateTimeParser.TryParseString("2024-01-15 14:30:45", out DateTime result))
{
Console.WriteLine($"Parsed: {result}");
}
else
{
Console.WriteLine("Failed to parse");
}
For repeated parsing with specific formats:
using WhatTimeIsIt;
// Create a parser instance
var parser = new DateTimeParser();
// Use default formats
DateTime dt1 = parser.Parse("2024-01-15 14:30:45.123456");
// Set custom formats for your specific needs
parser.Formats = new[]
{
"yyyy-MM-dd HH:mm:ss.ffffff",
"dd/MM/yyyy HH:mm:ss",
"MM/dd/yyyy HH:mm:ss"
};
DateTime dt2 = parser.Parse("15/01/2024 14:30:45");
// Reset to defaults when needed
parser.ResetToDefaults();
// SQL Server datetime2(7)
DateTime sqlServer = DateTimeParser.ParseString("2024-01-15 14:30:45.1234567");
// MySQL datetime with microseconds
DateTime mysql = DateTimeParser.ParseString("2024-01-15 14:30:45.123456");
// PostgreSQL timestamp
DateTime postgres = DateTimeParser.ParseString("2024-01-15T14:30:45.123456Z");
// Oracle with period separators
DateTime oracle = DateTimeParser.ParseString("15-Jan-24 14.30.45.123456");
// SQLite ISO 8601
DateTime sqlite = DateTimeParser.ParseString("2024-01-15T14:30:45.123Z");
// Unix timestamp (seconds since 1970-01-01)
DateTime unixSec = DateTimeParser.ParseString("1705329045");
// Unix timestamp (milliseconds)
DateTime unixMs = DateTimeParser.ParseString("1705329045000");
// .NET Ticks
DateTime ticks = DateTimeParser.ParseString("638405790450000000");
// Parse a datetime with microseconds
DateTime dt = DateTimeParser.ParseString("2024-01-15 14:30:45.123456");
// Access the full precision
long ticks = dt.Ticks;
Console.WriteLine($"Ticks: {ticks}");
// Extract microseconds
int totalMicroseconds = (int)(ticks % 10000000) / 10;
int milliseconds = totalMicroseconds / 1000;
int microseconds = totalMicroseconds % 1000;
Console.WriteLine($"Milliseconds: {milliseconds}, Microseconds: {microseconds}");
For scenarios where you need to preserve timezone offset information, use DateTimeOffsetParser instead of DateTimeParser.
DateTimeOffset can preserve the original timezone offset (like +05:00, -08:00) from the input string, while DateTime can only store UTC, Local, or Unspecified.
using WhatTimeIsIt;
// Parse with timezone preservation
DateTimeOffset dto = DateTimeOffsetParser.ParseString("2024-01-15T14:30:45+05:00");
Console.WriteLine(dto.Offset); // +05:00 - PRESERVED!
Console.WriteLine(dto.DateTime); // 2024-01-15 14:30:45
Console.WriteLine(dto.UtcDateTime); // 2024-01-15 09:30:45 (converted to UTC)
For datetime strings without timezone information, you can configure the default offset:
var parser = new DateTimeOffsetParser();
// Default is UTC (offset +00:00)
parser.DefaultOffset = TimeSpan.Zero;
var utc = parser.Parse("2024-01-15 14:30:45"); // Offset: +00:00
// Set to PST
parser.DefaultOffset = TimeSpan.FromHours(-8);
var pst = parser.Parse("2024-01-15 14:30:45"); // Offset: -08:00
// Set to India Standard Time
parser.DefaultOffset = TimeSpan.FromHours(5).Add(TimeSpan.FromMinutes(30));
var ist = parser.Parse("2024-01-15 14:30:45"); // Offset: +05:30
string input = "2024-01-15T14:30:45+05:00"; // India time
// With DateTime - offset is LOST, converted to local time
DateTime dt = DateTimeParser.ParseString(input);
Console.WriteLine(dt.Kind); // Local
Console.WriteLine(dt); // Converted to your local time (e.g., 01:30:45 in PST)
// With DateTimeOffset - offset is PRESERVED
DateTimeOffset dto = DateTimeOffsetParser.ParseString(input);
Console.WriteLine(dto.Offset); // +05:00 - Original offset preserved!
Console.WriteLine(dto.DateTime); // 2024-01-15 14:30:45 - Original time preserved!
Use DateTimeOffsetParser when:
Use DateTimeParser when:
DateTimeThis library may not be the best choice if:
You only need standard .NET parsing: If you're working with standard ISO 8601 or common .NET formats, DateTime.Parse() or DateTimeOffset.Parse() are simpler and faster.
You're working with single, well-known formats: If you know the exact format of your input, DateTime.ParseExact() or DateTimeOffset.ParseExact() is more efficient.
Performance is critical with known formats: The library tries multiple format patterns sequentially. For high-performance scenarios with predictable input, direct parsing is faster.
You need localized datetime strings: This library focuses on database and technical formats rather than user-facing localized datetime strings.
using WhatTimeIsIt;
public class DatabaseMigrator
{
private readonly DateTimeParser _parser = new DateTimeParser();
public DateTime ImportDateTimeFromAnyDatabase(string dateTimeString)
{
// Handles datetime strings from MySQL, SQL Server, Oracle, etc.
return _parser.Parse(dateTimeString);
}
}
using WhatTimeIsIt;
public class ApiResponseParser
{
public void ParseJsonResponse(string json)
{
// JSON might contain various datetime formats
var timestamps = ExtractTimestampsFromJson(json);
foreach (var timestamp in timestamps)
{
if (DateTimeParser.TryParseString(timestamp, out DateTime dt))
{
ProcessDateTime(dt);
}
}
}
}
using WhatTimeIsIt;
public class LogParser
{
public void ParseLogFile(string logContent)
{
var lines = logContent.Split('\n');
foreach (var line in lines)
{
// Extract timestamp from log line (various formats)
string timestampStr = ExtractTimestamp(line);
if (DateTimeParser.TryParseString(timestampStr, out DateTime timestamp))
{
var logEntry = new LogEntry
{
Timestamp = timestamp,
Message = line
};
ProcessLogEntry(logEntry);
}
}
}
}
using WhatTimeIsIt;
public class LegacySystemAdapter
{
private readonly DateTimeParser _parser;
public LegacySystemAdapter()
{
_parser = new DateTimeParser();
// Configure for specific legacy system formats
_parser.Formats = new[]
{
"yyyyMMddHHmmss",
"yyyy-MM-dd HH:mm:ss.fff",
"MMM dd yyyy hh:mm:ss:ffftt"
};
}
public DateTime ParseLegacyDateTime(string legacyDateTime)
{
return _parser.Parse(legacyDateTime);
}
}
The library supports over 100 datetime format patterns including:
See DateTimeParser.DefaultFormats for the complete list.
This project is licensed under the MIT License - see the file for details.
Contributions are welcome! Please feel free to submit issues or pull requests.
Current version: 1.0.0 - See for version history.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 net5.0 was computed. net5.0-windows net5.0-windows was computed. net6.0 net6.0 was computed. net6.0-android net6.0-android was computed. net6.0-ios net6.0-ios was computed. net6.0-maccatalyst net6.0-maccatalyst was computed. net6.0-macos net6.0-macos was computed. net6.0-tvos net6.0-tvos was computed. net6.0-windows net6.0-windows was computed. net7.0 net7.0 was computed. net7.0-android net7.0-android was computed. net7.0-ios net7.0-ios was computed. net7.0-maccatalyst net7.0-maccatalyst was computed. net7.0-macos net7.0-macos was computed. net7.0-tvos net7.0-tvos was computed. net7.0-windows net7.0-windows was computed. net8.0 net8.0 is compatible. net8.0-android net8.0-android was computed. net8.0-browser net8.0-browser was computed. net8.0-ios net8.0-ios was computed. net8.0-maccatalyst net8.0-maccatalyst was computed. net8.0-macos net8.0-macos was computed. net8.0-tvos net8.0-tvos was computed. net8.0-windows net8.0-windows was computed. net9.0 net9.0 was computed. net9.0-android net9.0-android was computed. net9.0-browser net9.0-browser was computed. net9.0-ios net9.0-ios was computed. net9.0-maccatalyst net9.0-maccatalyst was computed. net9.0-macos net9.0-macos was computed. net9.0-tvos net9.0-tvos was computed. net9.0-windows net9.0-windows was computed. net10.0 net10.0 was computed. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
| .NET Core | netcoreapp2.0 netcoreapp2.0 was computed. netcoreapp2.1 netcoreapp2.1 was computed. netcoreapp2.2 netcoreapp2.2 was computed. netcoreapp3.0 netcoreapp3.0 was computed. netcoreapp3.1 netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 netstandard2.0 is compatible. netstandard2.1 netstandard2.1 is compatible. |
| .NET Framework | net461 net461 was computed. net462 net462 was computed. net463 net463 was computed. net47 net47 was computed. net471 net471 was computed. net472 net472 was computed. net48 net48 was computed. net481 net481 was computed. |
| MonoAndroid | monoandroid monoandroid was computed. |
| MonoMac | monomac monomac was computed. |
| MonoTouch | monotouch monotouch was computed. |
| Tizen | tizen40 tizen40 was computed. tizen60 tizen60 was computed. |
| Xamarin.iOS | xamarinios xamarinios was computed. |
| Xamarin.Mac | xamarinmac xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos xamarinwatchos was computed. |
Showing the top 2 NuGet packages that depend on WhatTimeIsIt:
| Package | Downloads |
|---|---|
|
LiteGraph
LiteGraph is a property graph database with support for graph relationships, tags, labels, metadata, data, and vectors. |
|
|
SwiftStack
SwiftStack is an opinionated and easy way to build REST APIs, websockets APIs, and RabbitMQ interfaces, taking inspiration from the elegant model shown in FastAPI in Python. Built on Watson webserver. |
Showing the top 1 popular GitHub repositories that depend on WhatTimeIsIt:
| Repository | Stars |
|---|---|
|
litegraphdb/litegraph
Lightweight graph database with relational, vector, and MCP support, designed to power knowledge and artificial intelligence persistence and retrieval.
|
Initial release