Comments (4)
سلام
برای تبدیل تاریخ از string
به PersianDate
می تونید از کلاس PersianDateFormat
و متد parse
استفاده کنید.
مثال:
String sampleDate1 = '1401-10-10';
String sampleDate2 = '1401-10-13 22:10:15';
PersianDateFormat formater = new PersianDateFormat();
try{
PersianDate pDate1 = formater.parse(sampleDate1,'yyyy-MM-dd');
PersianDate pDate2 = formater.parse(sampleDate1,'yyyy-MM-dd HH:mm:ss');
}catch(){}
اطلاعات بیشتر در مستندات وجود داره.
from persiandate.
اگه pattern اش رو ندونم چی؟ یعنی یه آبجکتی که با initJalali ساختم.
from persiandate.
اگه قبلا ابجک PersianDate
به هر نحوی ساختید و می خوایید ازش string
بگیرید بهتره به جای استفاده از متد toString()
از PersianDateFormat
و متد format
استفاده کنید. اینجوری می تونید به هر فرمتی که بخوایید ازش string
تولید کنید و اگر نیاز داشتید دوباره با متد parse
به PersianDate
تبدیلش کنید.
مثال:
PersianDate pDate = new Persiandate();
String pDateString = PersianDateFormat.format(pdate,'Y m j');//return 1401 10 16 as a string
PersianDateFormat formater = new PersianDateFormat();
try{
PersianDate pDate2 = formater.parse(pDateString,'yyyy MM dd');
}catch(){}
from persiandate.
متوجه شدم خیلی ممنونم. ولی کاش یه راه حل یک خطی هم داشت. من از کاتلین استفاده میکنم، دوست ندارم هربار که آبجکت میسازم دو سه خط کد بنویسم. البته خودم میتونم حلش کنم ولی کاش این قابلیت وجود داشت.
from persiandate.
Related Issues (20)
- ماه های قمری HOT 1
- PersianDate init exception HOT 3
- Next day of month HOT 1
- Week HOT 5
- AddMonth Issue HOT 5
- persian date for compose desktop HOT 2
- Problem in time parsing HOT 2
- English Support for Month & Weekday Names HOT 4
- previous month calculation has bug HOT 2
- مشکل تابع initJalaliDate HOT 5
- problem in Converting persianDateString to Epoch HOT 2
- 'g' formatter value is is formatted to the same String as `H` HOT 2
- Doesn't compile on API levels lower than 26 HOT 1
- مشکل ساعت دقیقه و ثانیه HOT 1
- دریافت تاریخ یک ماه مشخص یا سال HOT 1
- چک کردن امروز است HOT 2
- به روز کردن خودکار مقدار shDay باتوجه به مقدار shMonth HOT 2
- تبدیل ساعت میلادی به شمسی HOT 3
- مشکل در سال 1402 HOT 12
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from persiandate.