Browsing 7239 questions and answers with Jon Skeet

How to parse a date with 24h time using joda?

How can I tell joda-time to automatically detect 24h Hour strings and parse them accordingly? DateTimeFormat.forPattern("YYYYMMDDhhmm").parseDateTime("201410171500"); Results...
Jon Skeet
people
quotationmark

You need to read the documentation for pattern characters very carefully: You want yyyy rather than YYYY, as you want regular calendar years rather than year-of-era. (Not likely to be significant in Joda Time, but if you port the code to... more 2/5/2015 9:42:42 AM

people

readDouble(); java programming

I tried to read the double value using read-double function but its reading as some other value, I gave the input as 15.00 it read as 825568816. please help me to get it...
Jon Skeet
people
quotationmark

Basically, don't use DataInputStream if you're trying to read text. DataInputStream is meant for streams of data written by DataOutputStream or something similar. Read the documentation for readDouble to see exactly what it's... more 2/5/2015 7:14:12 AM

people

Ant job adding escape character for String Password field

I have an Ant build that I am invoking from Jenkins. The Jenkins job has parameters, one of which is a password string ("Password Parameter" in Jenkins). The Ant target that...
Jon Skeet
people
quotationmark

It's got nothing to do with Ant - this is just the documented behaviour of Properties.store: Then every entry in this Properties table is written out, one per line. For each entry the key string is written, then an ASCII =, then the... more 2/4/2015 10:37:38 PM

people

remove an element from an XML

I want to remove an element from an XML Tree and I tried using the method mentioned in the following URL to do that. https://msdn.microsoft.com/en-us/library/bb387051.aspx My...
Jon Skeet
people
quotationmark

The Element method only returns a single element. You want: root.Elements("Child1").Elements("GrandChild1").Remove(); That uses: The normal XContainer.Elements method The Extensions.Elements extension method (on IEnumerable<T>... more 2/4/2015 9:12:05 PM

people

Passing unconstrained generic type parameter to a constrained method

I have too methods: public TValueType? DoStuffWithValueType<TValueType>(int x, int y) where TValueType: struct {} public TRefType...
Jon Skeet
people
quotationmark

You can't, basically - you'd have to invoke the relevant methods with reflection, which is ugly. Of course you can do this with dynamic typing, which hides the reflection from you: public T DoStuff<T>(int x, int y) { dynamic d =... more 2/4/2015 8:51:00 PM

people

Expression parsing Possible to get array of property names as string?

Is it possible to complete this method? Is it possible in the latest version of C#? Thinking about this as a DSL to configure a system for watching for certain property changes on...
Jon Skeet
people
quotationmark

In C# 6, you'd use: List<string> list = new List<string> { nameof(AccountOwner.AccountOwnerName), nameof(AccountOwner.AccountOwnerNumber) }; Before that, you could certainly break the expression tree apart - the... more 2/4/2015 7:56:55 PM

people

Why a String object has to be passed by reference?

In C#, for what I know, the passage of the parameters during a method call is by value. BUT when you use an object as an argument, what you pass is the reference of the object...
Jon Skeet
people
quotationmark

So, if I modify the value of a String inside a method, it should be modified when the method call is terminated (since String is an object in C#). But this isn't true, in fact if I write: You're not modifying the String object. You're... more 2/4/2015 6:44:03 PM

people

Why does a cast from int to float round the value?

I'm reading CS:APP, and regarding casts it says that when casting from int to float, the number cannot overflow, but it may be rounded. It seemed odd to me as I didn't know what...
Jon Skeet
people
quotationmark

I'm assuming that by float you mean a 32-bit IEEE-754 binary floating point value, by double you mean a 64-bit IEEE-754 binary floating point value, and by int you mean a 32-bit integer. Why does this happen? The range of float far... more 2/4/2015 4:01:57 PM

people

Objective c NSDateFormatter timezone reverts to GMT

I am playing about with some timezone calculations and I have noticed quite an annoying error which is causing me problems. If I create a date, use NSDateformatter to convert it...
Jon Skeet
people
quotationmark

I believe that the problem is that NSDate itself (i.e. the value you're logging at the end) doesn't have a time zone - it's just a moment in time. You're specifying the time zone *when formatting the value using stringFromDate*, and you're... more 2/4/2015 3:45:43 PM

people

Range of primitive type long in Java

I have found in documentation that range of long is from -2^63 to 2^63-1. When I run this for cycle I'm unable to get over cca 2 000 000 000. Log.d(TAG, "Long MAX = " +...
Jon Skeet
people
quotationmark

The problem is this line: long result = i * 184528125; The right hand side is evaluated in 32-bit integer arithmetic, because both operands are int. There's then an implicit conversion to long. To fix it, just make the RHS a long... more 2/4/2015 3:28:28 PM

people