Convert date and time to persian

forthebadge
platform ConvertDateAndTimeToPersian (1)

Install

Gradle

step 1.Add it in your root build.gradle at the end of repositories:

allprojects {
	repositories {
	...
	maven { url 'https://jitpack.io' }
	
    }
}

Step 2.Add the dependency

dependencies {
	   
	   implementation 'com.github.MohammadSadeghMehrafzoon:ConvertDateAndTimeToPersian:0.0.1'
}

Let's convert :)

Step 1. Define class and send time or date to it

=> kotlin
 
 val  timeAndDate = PersianTimeAndDate(dateAndTime) // for a time and date string
 val  date = PersianDate(date) //Just for the date
 val  time = PersianTime(time) //Just for the time
 
=> java

PersianDate date = new PersianDate(date); //Just for the date
PersianTime time = new PersianTime(time); //Just for the time
PersianTimeAndDate timeAndDate = new PersianTimeAndDate(dateAndTime); // for a time and date string

Step 2. Get the time or date converted

date.getPersianDate()
time.getPersianTime()
timeAndDate.getPersianDate()
timeAndDate.getPersianTime()

Example 1

 val  timeAndDate = PersianTimeAndDate("2023-01-28T13:15:00")
 timeAndDate.getPersianDate() // 1401/11/8 
 timeAndDate.getPersianTime() // 18:45
 

Or

val  timeAndDate = PersianTimeAndDate("2023/01/28T13:15:00")
timeAndDate.getPersianDate() // 1401/11/8 
timeAndDate.getPersianTime() // 18:45

Example 2

 val  date = PersianDate("2023-01-28")
 date.getPersianDate() // 1401/11/8 

Or

 val  date = PersianDate("2023/01/28")
 date.getPersianDate() // 1401/11/8