5

how I can get current Persian Date with time4Jin java?

PersianCalendar jalali = new PersianCalendar();
MOHS3N
  • 159
  • 1
  • 1
  • 11

2 Answers2

2

From the Javadoc of PersianCalendar:

PlainDate today = SystemClock.inLocalView().today();
PersianCalendar jalali = today.transform(PersianCalendar.class);
Erwin Bolwidt
  • 28,093
  • 15
  • 46
  • 70
  • The short form for this code is just: `PersianCalendar.nowInSystemTime()`. This refers to the usage of system timezone and system clock, but my comment (of the other answer) also shows options how to choose another timezone or another clock. – Meno Hochschild May 23 '18 at 15:23
1

I think there are multiple ways to do so:

  1. nowInSystemTime()

    PersianCalendar jalali = PersianCalendar.nowInSystemTime();
    
  2. using transformation

    PlainDate today = SystemClock.inLocalView().today();
    PersianCalendar jalali = today.transform(PersianCalendar.class);
    

Hope it helps!

Sergey Prokofiev
  • 1,635
  • 1
  • 11
  • 17
  • Yes, multiple ways. The first option is mainly for convenience. Users can also choose the timezone or the clock. Examples which also show that an explicit transformation is not necessary: `SystemClock.inZonalView(ASIA.TEHRAN).now(PersianCalendar.axis());` or a web-based clock `HttpClock hc = new HttpClock("http://www.google.com/"); jalali = hc.inLocalView().now(PersianCalendar.axis());` An SNTP-clock or a fixed test clock are also possible etc. – Meno Hochschild May 23 '18 at 15:19