Browsing 7239 questions and answers with Jon Skeet

How can I use the occurrences to calculate the end date of a recurring event in eas

Can anyone tell me the best way of calculating the end date of a recurring event from the number of occurrences and the pattern in which the event occurs. For example: I have an...
Jon Skeet
people
quotationmark

(This isn't an answer which gives you a complete solution by any means, but hopefully it's a step in the right direction.) Good luck. I've worked on an ActiveSync implementation, and recurrent events are fundamentally painful. You'll need... more 10/8/2014 3:30:10 PM

people

fmt:formatDate shows month too much

Im trying to show a date in my JSP page, with use of the fmt:formatDate tag. So in my JSP im doing this: <td><fmt:formatDate pattern="dd-MM-yyyy"...
Jon Skeet
people
quotationmark

This is the problem: cal.set(Calendar.MONTH, date.getMonth()); XMLGregorianCalendar uses a month range of 1-12. java.util.Calendar uses a month range of 0-11. You want: cal.set(Calendar.MONTH, date.getMonth() - 1); Also note that you... more 10/8/2014 11:56:16 AM

people

Why does java.util.Date represent Year as "year 1900"?

In java.util.Date: * In all methods of class <code>Date</code> that accept or return * year, month, date, hours, minutes, and seconds values, the * following...
Jon Skeet
people
quotationmark

Basically the original java.util.Date designers copied a lot from C. What you're seeing is the result of that - see the tm struct. So you should probably ask why that was designed to use the year 1900. I suspect the fundamental answer is... more 10/8/2014 11:40:28 AM

people

Parsing float resulting in strange decimal values

I'm attempting to parse a string with 2 decimal places as a float. The problem is, the resultant object has an incorrect mantissa. As it's quite a bit off what I'd expect, I...
Jon Skeet
people
quotationmark

From the documentation for System.Single: All floating-point numbers have a limited number of significant digits, which also determines how accurately a floating-point value approximates a real number. A Single value has up to 7... more 10/8/2014 11:33:38 AM

people

Regular Expression matching doesn't work

Hi all I am pretty new to regex world I am trying to match this regex "\bAsm_vidEmfUpdate_2 (0, ?unknown?)\b" with this string "Asm_vidEmfUpdate_2 (0, ?unknown?)". I tried to...
Jon Skeet
people
quotationmark

No, it's matching correctly but you only have a single group (the whole string). So Groups[1] is invalid - if you ask for Groups[0] it's fine: using System; using System.Text.RegularExpressions; class Program { static void... more 10/8/2014 11:27:15 AM

people

Synchronized thread method is executing concurrently why?

I have one question about thread. I have following Thread class and creating 2 thread objects. public class MyThread extends Thread{ String name=""; public...
Jon Skeet
people
quotationmark

Your synchronized method is effectively: private void callMe() { synchronized(this) { System.out.println("Started"); for (int i = 1; i <= 5; i++) { System.out.println(name+" = "+i); } ... more 10/8/2014 11:00:59 AM

people

Assembly.GetEntryAssembly() in NUnit

I am using NUnit to test one functionality where I need to load XML file to object. The XML file is in location of the Console Application. I have Following method where...
Jon Skeet
people
quotationmark

I suspect the problem is that NUnit is running your tests in a different AppDomain, but without using ExecuteAssembly. From the documentation for Assembly.GetEntryAssembly: Gets the process executable in the default application domain.... more 10/8/2014 10:34:04 AM

people

How to add point precision to decimal in C#?

I would like to know how I can add point precision to decimal. I made a small program to calculate the weekly pay for workers but in some cases when the results are like $145.60,...
Jon Skeet
people
quotationmark

Firstly, fix this line and similar ones: total = Convert.ToDecimal(hours * 7.50); In this particular case it's unlikely to be a problem, but you should try to avoid mixing double and decimal. You can just uese: decimal total = hours *... more 10/8/2014 10:12:44 AM

people

Convert UTC offset to USA time zone with Joda Time

Given a UTC offset, i.e. -5, can I determine the USA time zone using Joda Time? One of Pacific, Mountain, Central, Easter is sufficient. I can't use Java 8.
Jon Skeet
people
quotationmark

If you only have an offset, then no, you can't. -5 could be Central Daylight Time or Eastern Standard Time, for example. Likewise an offset of -7 could be Pacific Daylight Time or Mountain Standard Time. If you have an offset and a... more 10/7/2014 8:55:39 PM

people

Read bytes from file Java

I'm trying to parse my file which keeps all data in binary form. How to read N bytes from file with offset M? And then I need to convert it to String using new String(myByteArray,...
Jon Skeet
people
quotationmark

As of Java 7, reading the whole of a file really easy - just use Files.readAllBytes(path). For example: Path path = Paths.get("my_file.txt"); byte[] data = Files.readAllBytes(path); If you need to do this more manually, you should use a... more 10/7/2014 8:53:31 PM

people