B4J Library jCalendar

This is a wrapper for the GregorianCalendar and TimeZone classes, with its Java source code.

From the demo (in french because I used my default locale):
Full: mardi 29 novembre 2016 20 h 03 CET
Long: 29 novembre 2016 20:03:05 CET
Medium: 29 nov. 2016 20:03:05
Short: 29/11/16 20:03
Only date: 29/11/16

TimeZone: Europe/Paris (+1 h, use DST=true)

-1 week: 22/11/16 20:03:05
+2 days: 24/11/16 20:03:05
+27 hours and 65 minutes: 26/11/16 00:08:05

Difference between "1 janv. 2016 00:00:00.0" and "26 nov. 2016 00:08:05.364":
330 days
7920.135 hours
475208.089 minutes
28512485.364 seconds
 

Attachments

  • jCalendar v1.0.zip
    20.6 KB · Views: 524

Erel

B4X founder
Staff member
Licensed User
Longtime User
Note that you can use DateUtils with B4J: https://www.b4x.com/android/forum/t...fies-date-and-time-calcuations.26290/#content

It calculates the time difference differently. The time span is the accumulation of the components.

Example:
B4X:
Dim startDate As Long = DateUtils.SetDateAndTime(2016, 1, 1, 0, 0, 0)
Dim endDate As Long = DateUtils.SetDateAndTime(2016, 11, 26, 0, 8, 5)
Dim p As Period = DateUtils.PeriodBetween(startDate, endDate)
Log(p)
Dim p As Period = DateUtils.PeriodBetweenInDays(startDate, endDate)
Log(p)
Output:

Years=0, Months=10 , Days=25, Hours=0, Minutes=8, Seconds=5

Years=0, Months=0, Days=330, Hours=0, Minutes=8, Seconds=5


It is surprisingly difficult to get this result with the Java API.
 

Informatix

Expert
Licensed User
Longtime User
Note that you can use DateUtils with B4J: https://www.b4x.com/android/forum/t...fies-date-and-time-calcuations.26290/#content

It calculates the time difference differently. The time span is the accumulation of the components.

Example:
B4X:
Dim startDate As Long = DateUtils.SetDateAndTime(2016, 1, 1, 0, 0, 0)
Dim endDate As Long = DateUtils.SetDateAndTime(2016, 11, 26, 0, 8, 5)
Dim p As Period = DateUtils.PeriodBetween(startDate, endDate)
Log(p)
Dim p As Period = DateUtils.PeriodBetweenInDays(startDate, endDate)
Log(p)
Output:

Years=0, Months=10 , Days=25, Hours=0, Minutes=8, Seconds=5

Years=0, Months=0, Days=330, Hours=0, Minutes=8, Seconds=5


It is surprisingly difficult to get this result with the Java API.
Difference computations are not the reason why I wrapped the GregorianCalendar class (the original class does not provide functions computing a difference; it's something that I added to the wrapper). DateUtils is more complete on that matter, indeed (and can be used with jCalendar).
I wrapped GregorianCalendar because of how it deals with weeks and because it separates each field of the time value, so it becomes easy to group dates by weeks, months, semesters, etc.
I forgot to mention that jCalendar should work as is with Android.
 
Top