Browsing 7239 questions and answers with Jon Skeet

java 8 Instant.now() is showing wrong instant time

In Java 8 Instant.now() method showing wrong time . My code looks like : import java.time.*; import java.time.temporal.*; public class DateTimeDemo{ public static void...
Jon Skeet
people
quotationmark

That's the correct time. Note the "Z" at the end, indicating UTC - 11:01:25 in UTC is 16:31:25 in Asia/Calcutta. If you want to represent "now" in your default time zone, use ZonedDateTime.now() instead. more 7/11/2016 11:13:21 AM

people

How to get epoch limits of Java 8 chronology?

I am using the Java 8 Date and Time API in an application that uses both the Hijrah and Gregorian chronologies. The Hijrah calendar has a limited range support and will throw a...
Jon Skeet
people
quotationmark

You can use the Chronology.range() method. For example: import java.time.*; import java.time.chrono.*; import java.time.temporal.*; public class Test { public static void main(String[] args) { Chronology hijrah =... more 7/11/2016 8:10:07 AM

people

Contains doen't check in the date range

I have a date range come like this, string ActualReleaseDates ="7/8/2016, 7/9/2016, 7/11/2016,7/3/2016,7/10/2016,7/17/2016,7/24/2016,7/31/2016"; string NewsReleasedDate...
Jon Skeet
people
quotationmark

The immediate problem is that after splitting your ActualReleaseDates string, there isn't an entry of "7/11/2016"... instead, there's an entry of " 7/11/2016"... note the space. But more fundamentally, just trimming the start of... more 7/11/2016 6:56:01 AM

people

DateTime List find last date that before current

I have a list of dates: var dates = new List<DateTime> { new DateTime(2016, 01, 01), new DateTime(2016, 02, 01), new...
Jon Skeet
people
quotationmark

If your list is already sorted, you can use a binary search: var index = dates.BinarySearch(start); // If the precise value isn't found, index will be the bitwise complement // of the first index *later* than the target, so we need to... more 7/10/2016 7:54:31 PM

people

C# Generic methods and Calling way

static List<T> GetInitializedList<T>(T value, int count) { List<T> list = new List<T>(); for (int i = 0; i < count; i++) { ...
Jon Skeet
people
quotationmark

They're equivalent. Basically, if you don't specify the type arguments to the method (i.e. the types in the <> in the method invocation), the compiler will try to use type inference to work out which type arguments you meant, based... more 7/9/2016 3:47:36 PM

people

How do I get my hour, minutes, seconds, and milliseconds to be zeros?

I'm trying to get my format to be 2016-07-08T00:00:00.000Z. String myDate = "20160708"; LocalDate myLocalDate = LocalDate.parse(myDate,...
Jon Skeet
people
quotationmark

Well don't say "I want it to use the current time"! That's what this is doing: OffsetTime.now(ZoneOffset.UTC) If you just want an OffsetDateTime from a LocalDate by providing a zero offset and midnight, you can use: OffsetDateTime... more 7/8/2016 3:20:55 PM

people

Is NSDateFormatter correctly format my time zone?

I am using this code to create timezone stamps for the server interaction. NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; NSLocale *enUSPOSIXLocale = [NSLocale...
Jon Skeet
people
quotationmark

There's no formatting problem here - or at least, no bug in NSDateFormatter. It's behaving exactly as documented. From Unicode TR35-31, for 'Z' repeated 5 times: The ISO8601 extended format with hours, minutes and optional seconds... more 7/8/2016 1:53:59 PM

people

Strange effect of C# closures on garbage collector

Straight to the code class Program { private static WeakReference<EventHandler<EventArgs>> _noClosure; private static...
Jon Skeet
people
quotationmark

The compiler will cache the _noClosure delegate in a static field, and reuse it every time you call Init. The exact same instance can be reused every time. Compare that with _closure, which closes over a new instance of C() on each call... more 7/8/2016 1:26:32 PM

people

Passing function name to Func delegate

I have a very specific situation. I need to accept a function name from user and pass this function name (We already know that this function exists) to another method that handles...
Jon Skeet
people
quotationmark

So how do I pass a string as method name to another method that accepts Func<string, string>? You don't - you create a Func<string, string> instead. You can do that with Delegate.CreateDelegate: var method =... more 7/8/2016 11:53:59 AM

people

In Java, can the number of variables passed in value be less than the number of variables in the object's class?

This is an excerpt from Oracle's Java tutorial website. It doesn't show the actual .java files, but I'm guessing "Rectangle" is a class. But if you note, the parameters passed...
Jon Skeet
people
quotationmark

An object doesn't have parameters - a method or a constructor does. In this case, basically there are two overloaded constructors. For example: public Rectangle(Point origin, int width, int height) { this.origin = origin; ... more 7/7/2016 10:18:00 PM

people