How do you get the numeric day of the week? For instance, Sunday is day 1 in the Gregorian calendar. Using SimpleDateFormat, d gets the day in month. Any solution for the numeric day of week?
It should be "F" : http://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html
new SimpleDateFormat("F").format(new Date());
Related
i want to be set month from the year in the datePicker.
my date picker is start from today date. i want to set that any one can select only future date.
example : if today date is 05-09-2016 than year start from 2016 and go on.
month start from 09 ans show only 9,10,11,12 and if i select year 2017 then month show 1-to-12.
You can specify minDate as today by adding minDate: 0 to the options
$("input.DateFrom").datepicker({
minDate: 0,
...
});
Demo:
I am trying to retrieve the number of week in a month.. actually today is the second week in november but I am getting it as 3
The code I am using is
Log.e("dfhkdjfk", Calendar.getInstance().get(Calendar.WEEK_OF_MONTH)+"");
please help me to figure it out.
Reference Time:
3:45 AM
Monday, November 9, 2015
Coordinated Universal Time (UTC)
Wrong.
For some country like France where Monday is the first day of the week, today is really the first day of the third week of November, as the first of november was a Sunday ( so the first week of november had one day... ).
You might use DAY_OF_WEEK_IN_MONTH which give you the number of time a day already happened starting from the beginning of the current month.
Otherwise check which day is considered as the first of the week and implement some logic to adapt it to your need.
You need to try below code with TimeZone which give correct Calendar.WEEK_OF_MONTH
Calendar calUs = Calendar.getInstance(TimeZone.getTimeZone("US/Eastern"), Locale.US);
int weekOfMonthUs = calUs.get(Calendar.WEEK_OF_MONTH);
System.out.println("Week of month is " + weekOfMonthUs);
O/P
Week of month is the week within the current month starting from Sunday to how many weeks have there been.
WEEK_OF_MONTH depends on the first day of the week. Not all calendars have Sunday has beginning of the week. For ex: France has Monday as first day of the week. So Before getting into this check the locale of the phone.
There are some countries which first day of week begin on Sunday, instead other countries like mine begin on Monday. Is there any way to know which calendar is used in the country of the user.
I'm developing an application in Android with a calendar and I don't know how to solve this problem.
Set your country timeZone in Calendar class.
Calendar cal = Calendar.getInstance();
TimeZone tz = TimeZone.getTimeZone("GMT");
cal.setTimeZone(tz);
or
you can add the offset by if using UTC date or time.
I'm using SQLite on and Android device.
I am attempting to convert a timestamp to a julian day, and round down the julian day by casting the result to an integer. For some reason, 2456902.0 is being rounded to 2456901. (I get the same result with the 'round' function as well)
I do need a workaround, but I would also like an explanation as to why this is happening if anyone has one.
My code and results are listed below:
cast(julianday((c.ts/1000), 'unixepoch') as int) as day,
julianday((c.ts/1000), 'unixepoch') as jd
When ts = 1409564846705, jd = 2456902.0, day = 2456901 (datetime is Mon Sep 01 04:47:26 CDT 2014)
When ts = 1409631153881, jd = 2456902.8, day = 2456902 (datetime is Mon Sep 01 23:12:33 CDT 2014)
I am trying to convert the timestamp to julian days to group records by day, but some data is falling into the wrong day (as you can see above, two records will be produced if I group by day, but the dates are part of the same day). I've resorted to: strftime('%d', datetime((c.ts/1000), 'unixepoch', 'localtime')) as day. The problem with this is that if I query for more than a month, there will be duplicate 'day of month's. Is there a better way to do this?
Julian day numbers have integer values at noon, so the start of a day is halfway between integers:
> SELECT julianday(1409631153881/1000, 'unixepoch', 'start of day');
2456902.5
It does not make sense to round Julian day numbers to integers unless you define precisely whether you want the previous or the next noon.
If you want just to group by the day, convert the value into a date string:
date(c.ts / 1000, 'unixepoch', 'localtime')
If you want a value that can be converted into a number, combine the year and the day of the year:
cast(strftime('%Y%j', c.ts / 1000, 'unixepoch', 'localtime') as int)
Alternatively, just divide the timestamp by the number of milliseconds in a day, but then you need to substract the proper offset of the timezone.
When trying to get a string for the current date using
DateFormat.getDateInstance().format(calendar.getTime())
it keeps returning the wrong day. For example, it is saying today, July 25th., is July 26th. Also when I use it to sat a date picker, I get the day value by using
dayOfMonth = calendar.get(Calendar.DAY_OF_MONTH);
When the date picker is set, it also shows the day ahead by 1.
To get the calendar I'm using
Calendar calendar = Calendar.getInstance();
Is there something I'm missing?
Thanks
I would imagine this is because you havent set the timezone to your timezone, and rather than the day being off randomly, the time zone you are in is diferent than GMT (Greenwich Median? Time). Try looking at this example How to handle calendar TimeZones using Java?