How to get back the converted Time zone value? - c#

I am converting a datetime value to Indian Standard Time using the below code:
public DateTime GetdatetimedetailsinIST(DateTime datetimeinfo, String timeoffsetvalue)
{
string offset= timeoffsetvalue;
string timeZoneFormat = Convert.ToString("India Standard Time");
string strIndianTimezone = timeZoneFormat;
TimeZoneInfo tzinfoIndian = TimeZoneInfo.FindSystemTimeZoneById(strIndianTimezone);
DateTime dtDateTime = datetimeinfo.AddMinutes(Convert.ToInt32(offset));//ToUniversalTime();
dtDateTime = TimeZoneInfo.ConvertTimeFromUtc(dtDateTime, tzinfoIndian);
return dtDateTime;
}
Now I am calling GetdatetimedetailsinIST(5/6/2014 8:00:00 AM,"240");
and it will reurn Indian Time 5/6/2014 5:30:00 PM.
Now I want to get back the 5/6/2014 8:00:00 AM for another scenario by using value 5/6/2014 5:30:00 PM.
What are the changes need to do in the above function?
Please help.

howeverCould you add a string timeZoneToConvertTo parameter to your convert method?
public static DateTime DateTimeConvert(DateTime nonConvertedDateTime, string timeoffsetvalue, string timeZoneToConvertTo)
{
TimeZoneInfo tzinfo = TimeZoneInfo.FindSystemTimeZoneById(timeZoneToConvertTo);
DateTime dtDateTime = nonConvertedDateTime.AddMinutes(Convert.ToInt32(timeoffsetvalue));
dtDateTime = TimeZoneInfo.ConvertTimeFromUtc(dtDateTime, tzinfo);
return dtDateTime;
}
Console.WriteLine(DateTimeConvert(new DateTime(2014, 5, 6, 8, 00, 00), "240", "India Standard Time").ToString());
Console.WriteLine(DateTimeConvert(new DateTime(2014, 5, 6, 8, 00, 00), "240", "Central Standard Time").ToString());
You still need to handle any exceptions resulting from an inability to find the timezone.
I don't understand why you want an offset instead of using the ToUniversal() extension, however, that is your choice.

Adding minutes manually is seldom required or recommended. Also, there are a lot of unnecessary strings floating around your method. Consider the following instead:
public static DateTime ConvertToIndiaTime(DateTime dateTime, int offsetMinutes)
{
// Create a DateTimeOffset from the input values.
// This assumes positive offset values are *WEST* of UTC,
// such as if it came from the getTimeZoneOffset function of
// JavaScript's Date object.
TimeSpan offset = TimeSpan.FromMinutes(-offsetMinutes);
DateTimeOffset dto = new DateTimeOffset(dateTime, offset);
// Convert the DateTimeOffset to the desired time zone
DateTimeOffset converted =
TimeZoneInfo.ConvertTimeBySystemTimeZoneId(dto, "Indian Standard Time");
// Return the DateTime portion, representing the local time in India.
return converted.DateTime;
}
You would call it like this:
// get a DateTime object
DateTime dt = DateTime.ParseExact("5/6/2014 8:00:00 AM",
"M/d/yyyy h:mm:ss tt",
CultureInfo.InvariantCulture);
// get the offset as an integer
int offsetMinutes = 240;
// call the conversion method
DateTime indiaTime = ConvertToIndiaTime(dt, offsetMinutes);

Your method seems to combine two separate DateTime operations into one - hence it's not easy for you to reverse the operation. How about the following structure:
private static readonly TimeZoneInfo IstTimeZone =
TimeZoneInfo.FindSystemTimeZoneById("India Standard Time");
public static DateTime ConvertDateTimeUtcToIst(DateTime toConvert)
{
return TimeZoneInfo.ConvertTimeFromUtc(toConvert, IstTimeZone);
}
public static DateTime ConvertDateTimeIstToUtc(DateTime toConvert)
{
return TimeZoneInfo.ConvertTimeToUtc(toConvert, IstTimeZone);
}
Usage:
var converted = ConvertDateTimeUtcToIst(DateTime.Parse("5/6/2014 8:00:00 AM"))
.AddMinutes(240);
var reverted = ConvertDateTimeIstToUtc(converted).AddMinutes(-240);
Or if you absolutely need to have it in one method:
public static DateTime ConvertDateTimeUtcToIst(
DateTime toConvert, int offset = 0)
{
return TimeZoneInfo.ConvertTimeFromUtc(toConvert, IstTimeZone)
.AddMinutes(offset);
}
public static DateTime ConvertDateTimeIstToUtc(
DateTime toConvert, int offset = 0)
{
return TimeZoneInfo.ConvertTimeToUtc(toConvert, IstTimeZone)
.AddMinutes(offset);
}
Usage:
var converted = ConvertDateTimeUtcToIst(
DateTime.Parse("5/6/2014 8:00:00 AM"), 240);
var reverted = ConvertDateTimeIstToUtc(converted, -240);

Related

Create new DateTime in Country via TimeZoneInfo for office hours

Question
Q: How can I create a DateTime for e.g. 09:00 in Europe/Vienna
Catch: Most solutions that I've found already take a DateTime object and convert it but I want to CREATE it IN A SPECIFIC timezone knowing the timezone.
So it is not DateTimeKind.Utc and it is not DateTimeKind.Local it would be in DateTime in timezone.
Problem
P: TimeZoneInfo is not a parameter of DateTime. Why not? Could there be a simple extension?
Basis data:
1. string From = "09:00" //local time because summertime/wintertime
2. string Till = "17:00" //local time because summertime/wintertime
3. string TimeZoneResolved = "Europe/Vienna"
Implicitly I have:
TimeZoneInfo timeZoneInfo = TZConvert.GetTimeZoneInfo(TimeZoneResolved);
TimeSpan workHoursStart = TimeSpan.Parse(From);
TimeSpan workHoursEnd = TimeSpan.Parse(Till);
What I want to achieve:
//reconstruct today 9am in that country of timeZoneInfo
var now = DateTime.UtcNow;
var startTime = new DateTime(now.Year, now.Month, now.Day, workHoursStart.Hour, workHoursStart.Minute, 0, 0, timeZoneInfo);
-> invalid because TimeZoneInfo parameter is invalid. Expects DateTimeKind
Because constructor overload might be tricky maybe like that
var now = DateTime.UtcNow;
var officeHoursStart = new DateTime().BasedOnTz(timeZoneInfo, now.Year, now.Month, now.Day, workHoursStart.Hour, workHoursStart.Minute, 0, 0);
var officeHoursStartUtc = officeHoursStart.ToUtc();
To restate the problem - you have as input a time and a time zone, and you need as output the point in time that corresponds to that time on the current day in the given time zone.
Since the output is a point in time, you should prefer using DateTimeOffset. (If you must use a DateTime, you can take the .DateTime property from that.)
Since the input is a time of day, you should prefer using TimeOnly, available in .NET 6 and higher. (If you're using older .NET, then use a TimeSpan.)
Here's the general approach:
using System;
using System.Globalization;
// Get the time zone as a TimeZoneInfo object, either directly or via TimeZoneConverter.
TimeZoneInfo timeZone = TimeZoneInfo.FindSystemTimeZoneById("Eurpope/Vienna");
// Parse the time string. Prefer using TimeOnly (.NET 6+).
string timeString = "17:00";
TimeOnly time = TimeOnly.ParseExact(timeString, "HH:mm", CultureInfo.InvariantCulture);
// Or use TimeSpan on older .NET
// TimeSpan timeSpan = TimeSpan.ParseExact(timeString, "hh\\:mm", CultureInfo.InvariantCulture);
// Get the time on "today" with respect to the given time zone
DateTimeOffset timeTodayInTimeZone = time.OnTodayInTimeZone(timeZone);
You'll need some extension methods. Pick one of these, depending on which input you're using.
public static DateTimeOffset OnTodayInTimeZone(this TimeOnly time, TimeZoneInfo tz) =>
DateOnly.FromDateTime(TimeZoneInfo.ConvertTime(DateTime.UtcNow, tz))
.ToDateTime(time)
.ToDateTimeOffset(tz);
public static DateTimeOffset OnTodayInTimeZone(this TimeSpan time, TimeZoneInfo tz) =>
TimeZoneInfo.ConvertTime(DateTime.UtcNow, tz).Date
.Add(time)
.ToDateTimeOffset(tz);
And finally, you need this extension method that has the bulk of the logic.
(I've used this one on several other answers now.)
public static DateTimeOffset ToDateTimeOffset(this DateTime dt, TimeZoneInfo tz)
{
if (dt.Kind != DateTimeKind.Unspecified)
{
// Handle UTC or Local kinds (regular and hidden 4th kind)
DateTimeOffset dto = new DateTimeOffset(dt.ToUniversalTime(), TimeSpan.Zero);
return TimeZoneInfo.ConvertTime(dto, tz);
}
if (tz.IsAmbiguousTime(dt))
{
// Prefer the daylight offset, because it comes first sequentially (1:30 ET becomes 1:30 EDT)
TimeSpan[] offsets = tz.GetAmbiguousTimeOffsets(dt);
TimeSpan offset = offsets[0] > offsets[1] ? offsets[0] : offsets[1];
return new DateTimeOffset(dt, offset);
}
if (tz.IsInvalidTime(dt))
{
// Advance by the gap, and return with the daylight offset (2:30 ET becomes 3:30 EDT)
TimeSpan[] offsets = { tz.GetUtcOffset(dt.AddDays(-1)), tz.GetUtcOffset(dt.AddDays(1)) };
TimeSpan gap = offsets[1] - offsets[0];
return new DateTimeOffset(dt.Add(gap), offsets[1]);
}
// Simple case
return new DateTimeOffset(dt, tz.GetUtcOffset(dt));
}

c# DateTime. Reset time to 0

I have dateTime = 3/25/2020 1:25:46 PM
Can I reset time to zero? 3/25/2020 00:00:00
Here is a demo. In this case dateTime is 3/25/2020 12:00:00 AM
class Program
{
static void Main(string[] args)
{
var datetime = DateTime.Now;
datetime = ResetTimeToStartOfDay(datetime);
Console.WriteLine(datetime);
Console.ReadLine();
}
public static DateTime ResetTimeToStartOfDay(DateTime dateTime)
{
return new DateTime(
dateTime.Year,
dateTime.Month,
dateTime.Day,
0, 0, 0, 0);
}
}
How to reset the date to the beginning of the day?
more simply:
return dateTime.Date;
But note that in the specific case of DateTime.Now you could just use DateTime.Today instead.
How to reset the date to the beginning of the day?
You already are in your method ResetTimeToStartOfDay although there is an easier way to do it with dateTime.Date which is functionally equivalent.
So your question now becomes:
Why do you see 3/25/2020 12:00:00 AM instead of 3/25/2020 00:00:00 when Console.WriteLine(datetime); is called.
When you call ToString() on the DateTime instance, which happens implicitly in Console.WriteLine(datetime);, the displayed format matches the culture of the current thread which then displays the time using AM/PM. If you want to display the date as 3/25/2020 00:00:00 then call ToString() explicitly and pass a format string like M/d/yyyy HH:mm:ss
Console.WriteLine(datetime.ToString("M/d/yyyy HH:mm:ss"));
See also Custom date and time format strings
Try:
public static DateTime SetTimeToZero(DateTime YourDate)
{
return new DateTime(YourDate.Year, YourDate.Month, YourDate.Day, 0, 0, 0);
}
or you can create an ExtensionMethod and use inside your project:
public static DateTime SetTimeToZero(this DateTime YourDate)
{
return new DateTime(YourDate.Year, YourDate.Month, YourDate.Day, 0, 0, 0);
}
How to use ExtensionMethod:
yourDatetime.SetTimeToZero(date);

C# Get specific Date in ToInt64(milliseconds)

I just cannot figure this out....Damnit! Please see the calling method in the second code snippet. You'll see a commented out line that reads //_time = time.ToUTCString(); Go to the first code snippet to see the method ToUTCString(). You can see that it takes the datetime, converts it to Universal Time and subtracts the UnixEpoch to get the TotalSeconds. Then it converts that value to Int64() and finally to a string. I tried calling the methos ToLocalString but that's changing the date as well.
The date that I pass in is the date that I want to be converted to Int64 and eventually to a string. The datetime I pass in. Not changed.
I don't want to change the date that is passed in. I always pass in the date starting with 12:00:00AM (or 00:00:00) and that is the time I always want. Both of these methods change the date and or time. The date I pass in is 06/01/2017 12:00:00AM but sometimes it gets changed to 05/31/2017 04:00:00 or it keeps the date but the time is wrong. Dark Sky requires the date to be a value of Convert.ToInt64(milliseconds) and then converted to a string.
Does anybody know how to get the exact date and time that is passed in converted to Int64 using milliseconds?
I have the following Extensions class:
public static class Extensions
{
private static readonly DateTime UnixEpoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
public static DateTime ToDateTime(this Int64 _input)
{
return UnixEpoch.AddSeconds(_input);
}
public static string ToLocalString(this DateTime _input)
{
// _input = {6/1/2017 12:00:00 AM} System.DateTime
var milliseconds = _input.ToLocalTime().Subtract(UnixEpoch).TotalSeconds;
return Convert.ToInt64(milliseconds).ToString();
// I want to get the milliseconds for {6/1/2017 12:00:00 AM}
// I don't want the date or time to change
}
public static string ToUTCString(this DateTime _input)
{
// _input = {6/1/2017 12:00:00 AM} System.DateTime
var milliseconds = _input.ToUniversalTime().Subtract(UnixEpoch).TotalSeconds;
return Convert.ToInt64(milliseconds).ToString();
// I want to get the milliseconds for {6/1/2017 12:00:00 AM}
// I don't want the date or time to change
}
}
This is the calling method:
public ForecastIORequest(string apiKey, float latF, float longF, DateTime time, Unit unit, Language? lang = null, Extend[] extend = null, Exclude[] exclude = null)
{
_apiKey = apiKey;
_latitude = latF.ToString(CultureInfo.InvariantCulture);
_longitude = longF.ToString(CultureInfo.InvariantCulture);
//_time = time.ToUTCString();
_time = time.ToLocalString();
//DateTime t = _time.
_unit = Enum.GetName(typeof(Unit), unit);
_extend = (extend != null) ? RequestHelpers.FormatExtendString(extend) : "";
_exclude = (exclude != null) ? RequestHelpers.FormatExcludeString(exclude) : "";
_lang = (lang != null) ? RequestHelpers.FormatLanguageEnum(lang) : Language.en.ToString();
}
There's a fundamental problem with the way you're handling dates here, and if I boil it down to one thing, I think the problem is that ToUniversalTime() doesn't work the way you think it does.
What ToUniversalTime() does is, simply giving the UTC time of a time that's defined in a different time zone. For example, say my local time is UTC-7. So if I define a DateTime object without specifying DateTimeKind and set the value to, say, 2017/6/1 9:00:00, that means, at that time the actual UTC time is 2017/6/1 16:00:00 at that time, and ToUniversalTime() will give you a DateTime object with that value.
Let me change your ToUTCString() method a little bit and show you the problem with it. It's returning a long value instead of string now, and I break down the first line of code into two.
public static long ToUTC(this DateTime _input)
{
var utcTime = _input.ToUniversalTime();
var totalSeconds = utcTime.Subtract(UnixEpoch).TotalSeconds;
return Convert.ToInt64(totalSeconds);
}
And notice that in your Extensions class, the UnixEpoch object's DateTimeKind is set to UTC. I changed the date to 2017/6/1 8:00:00 for the ease of understanding.
private static readonly DateTime UnixEpoch = new DateTime(2017, 6, 1, 8, 0, 0, DateTimeKind.Utc);
public static DateTime ToDateTime(this Int64 _input)
{
return UnixEpoch.AddSeconds(_input);
}
Now let's call that method with a DateTime object whose DateTimeKind is set to UTC.
// dateObj will have time 2017/6/1 9:00:00 _in UTC_.
var dateObj = new DateTime(2017, 6, 1, 9, 0, 0, DateTimeKind.Utc);
// This method converts to UTC, but it's already in UTC, so no actual conversion takes place.
// Then subtracts UnixEpoch from it, which is also in UTC.
long dateInLong = dateObj.ToUTC();
// The difference is one hour, so dateInLong will be 3600.
Console.WriteLine(dateInLong);
// This method adds the above difference to UnixEpoch, and displays the time.
Console.WriteLine(dateInLong.ToDateTime());
Now, here, everything is in UTC and you should see output as expected, like below:
3600
6/1/2017 09:00:00
All good so far.
Now change things a bit, and let's set our dateObj to local instead of UTC, as you do in your example.
// Notice that the object is in local time now.
var dateObj = new DateTime(2017, 6, 1, 9, 0, 0);
long dateInLong = dateObj.ToUTC();
Console.WriteLine(dateInLong);
Console.WriteLine(dateInLong.ToDateTime());
Now, the above dateObj will have time 9:00:00, but in my local time. My actual location is UTC-7 so note that this means 9AM local time for me is 4PM UTC. But note that we haven't changed the UnixEpoch object, which is still in UTC and time is set to 8AM UTC in it. And therefore, dateInLong will be 28,800 (8 hours x 60 mins x 60 seconds). So when your ToDateTime() method is called, it adds 28,000 seconds to 8AM UTC time, and returns as a DateTime object, of which time now is 4PM UTC.
28800
6/1/2017 16:00:00
And that's why depending on the time you set your dateObj to, your output changes time as you said.
Solution
You need to decide which time zone to use, and stick to that. One option would be to get rid of all the UTC conversions and have all times set in local time.
public static class Extensions
{
// NOT set to UTC
private static readonly DateTime UnixEpoch = new DateTime(2017, 6, 1, 8, 0, 0);
public static DateTime ToDateTime(this Int64 _input)
{
return UnixEpoch.AddSeconds(_input);
}
public static long ToUTC(this DateTime _input)
{
// NOT converted to UTC. So... change variable names accordingly.
var utcTime = _input;
var totalSeconds = utcTime.Subtract(UnixEpoch).TotalSeconds;
return Convert.ToInt64(totalSeconds);
}
}
class Program
{
static void Main(string[] args)
{
// Notice that the object is in local time and NOT UTC.
var dateObj = new DateTime(2017, 6, 1, 9, 0, 0);
long dateInLong = dateObj.ToUTC();
Console.WriteLine(dateInLong);
Console.WriteLine(dateInLong.ToDateTime());
Console.ReadLine();
}
}
The other option, set EVERYTHING to UTC, but then you'll have to make sure that the DateTime object on which you call ToUTC() is defined in UTC and not local.
So:
private static readonly DateTime UnixEpoch = new DateTime(2017, 6, 1, 8, 0, 0, DateTimeKind.Utc);
And
var utcTime = _input.ToUniversalTime();
And finally
var dateObj = new DateTime(2017, 6, 1, 9, 0, 0, DateTimeKind.Utc);
BUT...
I see a bigger problem with you code, looking at the second code snippet. In the ForecastIORequest() constructor, you're saving time as a string. And that's not an ideal solution in my opinion. Because as you found the hard way, depending on what time zone the calling object was created, your time difference will be, well, different. And you'd have no way of knowing which.
I'd rather store the DateTime object as it is, and read it and calculate the difference when needed, taking into account time zones.
Hope this helps.
See DateTime.Ticks - there are 10,000 ticks in a millisecond. Simply take DateTime.Ticks / 10000 (ten thousand) and you have your milliseconds.
Here's a simple extension method to get the milliseconds as a long (that's Int64):
public static long ToMilliseconds(this DateTime dateTime)
{
return dateTime.Ticks / 10000;
}

How to convert DateTimeOffset back to DateTime

When we create a search index and we define a field as DateTime the type is Edm.DateTimeOffset. And the value should be like this: yyyy-MM-ddTHH:mm:ss.fffZ or yyyy-MM-ddTHH:mm:ss.fff[+|-]HH:mm.
Now I have a file in my database of type DateTime that get's converted to Offset like this:
DateTime offset = //get from database the date
TimeZoneInfo zone = TimeZoneInfo.FindSystemTimeZoneById("FLE Standard Time");
DateTimeOffset offsetConverted = new DateTimeOffset(offset, zone.GetUtcOffset(offset));
My question: how can I convert offsetConverted to my orginal DateTime offset?
Use the DateTime property of the DateTimeOffset class to convert the DateTimeOffset to a DateTime.
using System;
namespace StackOverflowProblem1
{
class Program
{
static void Main(string[] args)
{
// input comes from user in form yyyyddMMTHHmmss
DateTime offset = new DateTime(2016, 10, 12, 12, 22, 0);
TimeZoneInfo zone = TimeZoneInfo.FindSystemTimeZoneById("FLE Standard Time");
DateTimeOffset offsetConverted = new DateTimeOffset(offset, zone.GetUtcOffset(offset));
DateTime roundTripOffset = offsetConverted.DateTime;
Console.WriteLine("Input {0}, as DateTimeOffset {1},",
offset.ToString(),
offsetConverted.ToString());
Console.WriteLine("after round trip {0}, Kind {1}.",
roundTripOffset,
roundTripOffset.Kind);
}
}
}
Console output:
Input 10/12/2016 12:22:00, as DateTimeOffset 10/12/2016 12:22:00 +03:00,
after round trip 10/12/2016 12:22:00, Kind Unspecified.

Inconsistent DateTime to Unix Time conversion and error on 24 hour input

Attached is a method I am currently using that takes in a list of DateTime strings, their input format (i.e. yyyy-MM-dd HH:mm:ss), and their offset in the form of hours.
As for the culture and "standard", I am using InvariantCulture and I am converting the times to UTC.
public int unixFormat3(string dateTimeInput, string inputFormat, int hours)
{
DateTime result;
CultureInfo provider = CultureInfo.InvariantCulture;
result = DateTime.ParseExact(dateTimeInput, inputFormat, provider);
int unixTime = (Int32)(result.ToUniversalTime().AddHours(hours).Subtract(new DateTime(1970, 1, 1, 0, 0, 0, 0, System.DateTimeKind.Utc))).TotalSeconds;
return unixTime;
}
Two issues with said method:
I am using this website as a comparison. If my input is 2014-03-18 21:00:00, my output, according to my method, is 1395190800, which converts back to 2014-03-19 01:00:00. It has a four hour difference. The desired output is this:
If my input is 2014-03-18 24:00:00, I get this error:
The DateTime represented by the string is not supported in calendar System.Globalization.GregorianCalendar.
Noticeably, it does not allow the input of 24 in the HH part. This is a weird error as NodaTime handles it just fine... Though that's irrelevant as I am using DateTime.
Does anyone have any insight on this area?
EDIT:
Upon some experimentation, removing the .ToUniversalTime() removes my 4-hour offset.. Why is this happening?
public int unixFormat3(string dateTimeInput, string inputFormat, int hours)
{
DateTime result;
CultureInfo provider = CultureInfo.InvariantCulture;
result = DateTime.ParseExact(dateTimeInput, inputFormat, provider);
int unixTime = (Int32)(result.AddHours(hours).Subtract(new DateTime(1970, 1, 1, 0, 0, 0, 0, System.DateTimeKind.Utc))).TotalSeconds;
return unixTime;
}
This document, http://www.w3.org/TR/NOTE-datetime, cited in this question How to know whether a given string is a valid UTC DateTime format? does not list 24 as a valid hour value.
This document, http://en.wikipedia.org/wiki/Iso8601, cited by an answer to the question does list 24:00 as a valid time. This one, http://en.wikipedia.org/wiki/12-hour_clock#Confusion_at_noon_and_midnight, also says 24:00 is valid.
The System.DateTime object represents hours as an integer value between 0 and 23 (see http://msdn.microsoft.com/en-us/library/vstudio/system.datetime.hour(v=vs.100).aspx). As far as I know, NodaTime doesn't use any of the .NET provided DateTime or DateTimeOffset classes and handles everything itself, which is why it's handling an hour of 24 correctly.
As for why ToUniversalTime() is adding an offset, its probably because the ParseExact is returning a date that's already been adjusted. (What is the value of result just before you call ToUniversalTime()?)
You may also want to change your call to use this overload of ParseExact instead:
result = DateTime.ParseExact(dateTimeInput, inputFormat, provider, DateTimeStyles.AssumeUniversal | DateTimeStyles.AdjustToUniversal);
This tells the parser to assume the time is in UTC if no time zone is specified in the parsed string.
As a side note, you should probably declare your Unix epoch as a readonly global variable somewhere and use TryParseExact instead of ParseExact.
public class UnixTime
{
public static readonly DateTime Epoch = new DateTime(1970, 1, 1, 0, 0, 0, 0, System.DateTimeKind.Utc);
public int unixFormat3(string dateTimeInput, string inputFormat, int hours)
{
int unixTime = -1;
DateTime result = DateTime.MinValue;
if (DateTime.TryParseExact(dateTimeInput, inputFormat, CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal | DateTimeStyles.AdjustToUniversal, out result))
{
unixTime = (int)(result.AddHours(hours).Subtract(UnixTime.Epoch)).TotalSeconds;
}
return unixTime;
}
}

Categories

Resources