How to get the integer value of day of week
Use day1 = (int)ClockInfoFromSystem.DayOfWeek;
Use day1 = (int)ClockInfoFromSystem.DayOfWeek;
Firstly, separate out the conversion part from the formatting/parsing part. You can deal with those easily later – and there are lots of questions on Stack Overflow about that. Personally I’d use Joda Time, which typically makes life much simpler. For example: import org.joda.time.Chronology; import org.joda.time.LocalDate; import org.joda.time.chrono.IslamicChronology; import org.joda.time.chrono.ISOChronology; public class Test { public … Read more
The lubridate package has a function, date_decimal that you can use for this. x <- c(1988.0, 1988.25, 1988.5, 1988.75) library(lubridate) (f <- format(date_decimal(x), “%d-%m-%Y”)) # [1] “01-01-1988” “01-04-1988” “02-07-1988” “01-10-1988” Then you can write it to a csv with write.csv(f, “afilename.csv”) ## or write.table() You’ll probably want to check the output first and adjust some … Read more
Using SimpleDateFormat String string_date = “12-December-2012”; SimpleDateFormat f = new SimpleDateFormat(“dd-MMM-yyyy”); try { Date d = f.parse(string_date); long milliseconds = d.getTime(); } catch (ParseException e) { e.printStackTrace(); }
SQL Server 2008 and up In SQL Server 2008 and up, of course the fastest way is Convert(date, @date). This can be cast back to a datetime or datetime2 if necessary. What Is Really Best In SQL Server 2005 and Older? I’ve seen inconsistent claims about what’s fastest for truncating the time from a date … Read more
SimpleDateFormat format1 = new SimpleDateFormat(“yyyy-MM-dd”); SimpleDateFormat format2 = new SimpleDateFormat(“dd-MM-yyyy”); Date date = format1.parse(“2013-02-21”); System.out.println(format2.format(date));
It’s over the web. Could have googled. Anyways, here is a version for you (shamelessly picked and modified from here): Calendar calendar = Calendar.getInstance(); TimeZone fromTimeZone = calendar.getTimeZone(); TimeZone toTimeZone = TimeZone.getTimeZone(“CST”); calendar.setTimeZone(fromTimeZone); calendar.add(Calendar.MILLISECOND, fromTimeZone.getRawOffset() * -1); if (fromTimeZone.inDaylightTime(calendar.getTime())) { calendar.add(Calendar.MILLISECOND, calendar.getTimeZone().getDSTSavings() * -1); } calendar.add(Calendar.MILLISECOND, toTimeZone.getRawOffset()); if (toTimeZone.inDaylightTime(calendar.getTime())) { calendar.add(Calendar.MILLISECOND, toTimeZone.getDSTSavings()); } System.out.println(calendar.getTime());
The second parameter to date() needs to be a proper timestamp (seconds since January 1, 1970). You are passing a string, which date() can’t recognize. You can use strtotime() to convert a date string into a timestamp. However, even strtotime() doesn’t recognize the y-m-d-h-i-s format. PHP 5.3 and up Use DateTime::createFromFormat. It allows you to … Read more