I have an application in C# where I want to show the Start Date from the server... I mean the real date since the server is running....
The goal is to know if the server went down in any moment.
I´m not sure but it has to be any class in C# to be able to get this datetime from the server...
if you execute in the console "net statistics server"... you display exactly the time i mean...
any idea`?
Thanks in advance!
DateTime start =
DateTime.Now -
TimeSpan.FromMilliseconds(System.Environment.TickCount);
Related
My dates are being stored in sql server.
Windows server region and timezone are correct, but when I see the date in database it's increased by 3 hours, I think it is comming from some server configuration that is overriding, but don't know where else to look.
When I send date from local project to production database, it saves correctly, but when I use production website it doesn't.
Where else should I check to solve this?
It depends on the codebase running your production portal.
Use Datetime as utc and cater for it accordingly. Or add DatetimeOffset and calculate the difference when needed.
If you still have the luxury of refactoring, I advise you to take a little dive into the Dates and time handling, get a solid understanding of it, then code accordingly, so it doesn't fire back on you in later stages or usages.
The problem was in some machines of the load balance, there are several machines created from an image, the original was right but the copies were not, if I tried many times to save the registry, then I happened to be redirected to the machine with the correct configuration and then the record was saved with the correct date.
I just asked devops to correct the settings on the other machines.
If you want to get advantage of your local machine timezone you can use myDateTime.ToUniversalTime() to get the UTC time from your local time or myDateTime.ToLocalTime() to convert the UTC time to the local machine's time.
// convert UTC time from the database to the machine's time
DateTime databaseUtcTime = new DateTime(2011,6,5,10,15,00);
var localTime = databaseUtcTime.ToLocalTime();
// convert local time to UTC for database save
var databaseUtcTime = localTime.ToUniversalTime();
If you need to convert time from/to other timezones, you may use TimeZoneInfo.ConvertTime() or TimeZoneInfo.ConvertTimeFromUtc().
// convert UTC time from the database to japanese time
DateTime databaseUtcTime = new DateTime(2011,6,5,10,15,00);
var japaneseTimeZone = TimeZoneInfo.FindSystemTimeZoneById("Tokyo Standard Time");
var japaneseTime = TimeZoneInfo.ConvertTimeFromUtc(databaseUtcTime, japaneseTimeZone);
// convert japanese time to UTC for database save
var databaseUtcTime = TimeZoneInfo.ConvertTimeToUtc(japaneseTime, japaneseTimeZone);
I'm working with two servers (Server 2012 Std) and (Server 2016).
On 2012 when I run the command:
[System.DateTime]::UtcNow.ToString([System.Globalization.CultureInfo]::GetCultureInfo("en-NZ"))
I get back the result:
13/03/2018 12:49:55 a.m.
When I run the same command as above on my Server 2016 I get back:
13/03/2018 12:48:42 AM
They key part is the AM/PM formatting. I'm trying to understand why these are returning different results and how to get the server 2016 output to be formatted the same as the first. This is due to an application requirement and I do not have access to change the application to format the string so I have to resolve this at the OS level somehow.
Take a look at Output of times (AM/PM) changed in Windows 10 when using DateTime.ToString("tt") for some discussion of this.
It doesn't appear that you will be able to fix this without changing application code.
I found the same problem and I was able to get around the issue by using the following code. Not sure if that's what your looking for.
[System.DateTime]::UtcNow.ToString("dd/MM/yyyy hh:mm:ss tt")
I have developed a website and want to send an auto-generated mail to new user's regarding the website on every 3rd day from their registration day.
I don't know is it possible or not. If it is possible, can I know how ?
Thanks for the help..
To get every day the users who are 3,6,9 days old etc. you need to run daily a SQL statement along the lines of (this is T-SQL syntax):
SELECT UserName, EMail FROM Users WHERE (cast(RegistrationDate as int) - cast (GETDATE() as int)) % 3 = 0 AND RegistrationDate > GETDATE()
As to which method to use for your daily task, as we say in English "you pay your money and you take your choice". However, I do not think it a good idea to have a timer on your website just to do a once a day job. Better would be something like Task Scheduler on Windows or cron on Unix/Linux.
Using C#
Write a console application to get the dataset of users whose registered date is meeting 3 days bucket & send email using smtp
Build & get .exe file to configure in Task scheduler on your required schedule
Refer this
Using SQL
Use sp_send_dbmail in SQL server to distribute email
SO thread
I've developed an MVC 4 with C# application which I've deployed using Windows Azure to their datacenter in Virginia. I log user activity in my application recording both the username and the time that an activity was initiated. The time recorded needs to be converted to Fiji Standard Time. Based on what I have found online I wrote an extension method to help achieve this functionality.
public static DateTime ToFijiTime(this DateTime datetime)
{
datetime = DateTime.SpecifyKind(datetime, DateTimeKind.Utc);
TimeZoneInfo tz = TimeZoneInfo.FindSystemTimeZoneById("Fiji Standard Time");
DateTime MyDateTime = TimeZoneInfo.ConvertTime(datetime, tz);
return TimeZoneInfo.ConvertTimeToUtc(MyDateTime, tz);
}
However this doesn't really work well once it's deployed. I get the right date and almost the right time. For some reason it always gives the time as an "am" time. For example if the time should be 2/04/2013 6:30:19 PM (Fiji Standard Time)The time recorded is actually 2/04/2013 6:30:19 AM (Fiji Standard Time) but times that are in the morning like2/04/2013 1:30:19 AM are saved correctly. Can anyone please tell me what's wrong with my code?
Store the users timezone server side then,
Use following:
#TimeZoneInfo.ConvertTimeFromUtc(Model.CreatedOn, TimeZoneInfo.FindSystemTimeZoneById("E. US Standard Time"))
Also refer this :
Convert UTC/GMT time to local time
i have WebService in the PC
and i get date & time in dd/mm/yyyy and on another PC in mm/dd/yyyy
i have any Windows-CE mobile that connect to this PC
how to Synchronize date & time between PC and mobile ?
(i need that the PC date & time will be in the monile)
thank's in advance
Your web service should expose the date and time in a standard format (e.g. ISO-8601). If your web method is declared to return a DateTime, this should happen automatically - the situation you've described should only occur if you're explicitly doing something like:
return DateTime.UtcNow.ToString("d");
... don't do that, basically.
Convert the date of your Smartphone to ISO format (i.e. yyyy-mm-dd) then send it to your PC and convert it there from yyyy-mm-dd to mm/dd/yyyy