Browsing 7239 questions and answers with Jon Skeet

Best class to keep track of a fictional date in time? (Java)

I'm making a video game in Java and I ran into a problem where I need date to be managed accurately. The game will start off somewhere in 2010 and it needs to continue on day...
Jon Skeet
people
quotationmark

You should either use Joda Time if you're still using Java 7 or earlier (in which case you should also be looking to move to Java 8), or the java.time package if you're using Java 8. In both cases, you want the LocalDate class, which is... more 10/6/2015 9:21:50 PM

people

DateTime format one digit day not recognized

I need to read a String in the following format: "6102015" (meaning October 6th, 2015) and turn it into DateTime objects. I tried the following code, which did not...
Jon Skeet
people
quotationmark

Is there a way to read this date format without having to add the 0? Adding a 0 is the least of your worries, IMO. That takes one line of code. Assuming you've got a copy of the database or something you can alter, effectively, I... more 10/6/2015 9:17:11 PM

people

How do I create a DateTime object given UTC time and date?

I have date and time strings already in UTC. I need to use those strings to create a DateTime object. This is the code I'm using. The problem is the time gets converted and my...
Jon Skeet
people
quotationmark

D Stanley's answer certainly works, but is slightly more complex than you need - if you want a DateTime as the result, you don't need to use DateTimeOffset at all, as DateTime.ParseExact handles DateTimeStyles.AssumeUniversal as well,... more 10/6/2015 7:49:47 PM

people

Variable not within scope using HttpWebRequest and WebResponse

I am having an issue with my variable httpRes. Basically this is the basics of a command line app that will check a set of given URL's and return their status code, i.e....
Jon Skeet
people
quotationmark

Well if you catch an exception, that would probably be because GetResponse failed, right? So you wouldn't have assigned anything to httpRes yet... It seems to me that you should be catching WebException, at which point you can look at... more 10/6/2015 6:54:12 PM

people

Java static initialization thread safety guarantee in language spec

It is commonly accepted that static initialization is thread safe. It is guaranteed to only happen once. I am however curious exactly where in the language spec does it state that...
Jon Skeet
people
quotationmark

I believe this is effectively a result of the rules for class initialization in JLS 12.4.2. That involves synchronizing on a lock, only releasing it after executing the static initializers and field initializers. That lock acquisition and... more 10/6/2015 6:32:31 PM

people

C# inheritance build errors

I am new to Stack Overflow and a neophyte programmer. I am trying to build in Visual Studio 2010 C# someone else’s code as a learning opportunity. I am unable to figure out why...
Jon Skeet
people
quotationmark

The problem is here: public class c_abstract_button_widget: c_basic_object { public c_basic_object(string p_name) : base(p_name) { //Console.WriteLine("Inside c_abstract_button_widget "); } } To declare a... more 10/6/2015 5:50:17 PM

people

JSR 310 :: System.currentTimeMillis() vs Instant.toEpochMilli() :: TimeZone

Could you please shed some light on how to obtain correct epoch time in milliseconds for a default system timezone and given timezone. Given 1. TimeZone: GMT+3 2. The following...
Jon Skeet
people
quotationmark

Both System.currentTimeMillis() and Instant.toEpochMilli() return the number of milliseconds since the Unix epoch. That isn't "in" any particular time zone, although the Unix epoch is normally expressed as "midnight on January 1st 1970,... more 10/6/2015 4:55:51 PM

people

Why does .Net allow ambiguous methods such as these

Currently I'm using .Net 3.5 so please let me know if it has been fixed in a later version. Currently I have 2 methods with the following signatures: void Method1(string,...
Jon Skeet
people
quotationmark

how does the compiler know which method to call? It follows the overload resolution rules listed in the C# language specification. In particular, in section 7.5.3.2 (looking at the C# 4 spec, but I believe C# 5 has the same numbering... more 10/6/2015 3:11:00 PM

people

Converting InputStream.read() to numbers (not integers)

I've been struggling to get a part of my program working. After about a week of trial and error I don't think I'm able to do this without any help. Here's the case: I've written...
Jon Skeet
people
quotationmark

It should be translated to 1444109725 Well, I suspect it should actually be translated to 1444109725760, which is what the bytes represent when read as a big-endian 64-bit integer. You then treat that as milliseconds since the Unix... more 10/6/2015 11:13:08 AM

people

How to perform multiplication in date (datetimeoffset format)

I have following 3 fields startingdate, expirydate, number of months startingdate = DateTimeOffset.Now; and number of months, say 24 months How to calculate expirydate =...
Jon Skeet
people
quotationmark

You don't need multiplication in this case - just addition, specifying the units: DateTimeOffset startDate = DateTimeOffset.Now; DateTimeOffset expiryDate = startDate.AddMonths(months); Two things to note: Date and time arithmetic can... more 10/6/2015 6:11:48 AM

people