gregorian-calendar

Specify the date format in XMLGregorianCalendar

穿精又带淫゛_ 提交于 2019-11-27 20:32:54
I want to use a Date in XMLGregorianCalendar format for sending to a web service. The web service expects information in yyyy-dd-mm format. I use the below code to create an XMLGregorianCalendar and send it to web service. Date dob = null; DateFormat df = new SimpleDateFormat("dd/MM/yyyy"); try { XMLGregorianCalendar date2; dob = df.parse("13/06/1983"); GregorianCalendar c = new GregorianCalendar(); c.setTimeInMillis(dob.getTime()); date2 = DatatypeFactory.newInstance().newXMLGregorianCalendar(c); System.out.println(date2); } catch(DatatypeConfigurationException e) { // TODO Auto-generated

Displaying the last two digits of the current year in Java

醉酒当歌 提交于 2019-11-27 17:25:17
问题 How can I display only the last two digits of the current year without using any substring algorithms or any third party libraries? I have tried the below method and it gave a four-digit year. I want to know whether there are any date formatting options available to get the current year in two-digit format. Calendar.getInstance().get(Calendar.YEAR); 回答1: You can use a SimpleDateFormat to format a date as per your requirements. DateFormat df = new SimpleDateFormat("yy"); // Just the year, with

converting gregorian to hijri date

偶尔善良 提交于 2019-11-27 12:53:55
I want to convert from Gregorian to Hijri(Islamic) date and I need a java class for this converting. I want to give it an Gregorian date in format of "yyyy/mm/dd" as string and it give me the Hijri date in the same format. can anyone help me? Jon Skeet Firstly, separate out the conversion part from the formatting/parsing part. You can deal with those easily later - and there are lots of questions on Stack Overflow about that. Personally I'd use Joda Time , which typically makes life much simpler. For example: import org.joda.time.Chronology; import org.joda.time.LocalDate; import org.joda.time

Simple conversion between java.util.Date and XMLGregorianCalendar

蹲街弑〆低调 提交于 2019-11-27 10:08:18
I'm looking for a simple method of converting between java.util.Date and javax.xml.datatype.XMLGregorianCalendar in both directions. Here is the code that I'm using now : import java.util.GregorianCalendar; import javax.xml.datatype.DatatypeConfigurationException; import javax.xml.datatype.DatatypeFactory; import javax.xml.datatype.XMLGregorianCalendar; /** * Utility class for converting between XMLGregorianCalendar and java.util.Date */ public class XMLGregorianCalendarConverter { /** * Needed to create XMLGregorianCalendar instances */ private static DatatypeFactory df = null; static { try {

Converting Gregorian date to Hijri date

会有一股神秘感。 提交于 2019-11-27 01:38:35
问题 How do you convert Gregorian dates to Islamic Hijri dates using JavaScript? 回答1: function gmod(n,m){ return ((n%m)+m)%m; } function kuwaiticalendar(adjust){ var today = new Date(); if(adjust) { adjustmili = 1000*60*60*24*adjust; todaymili = today.getTime()+adjustmili; today = new Date(todaymili); } day = today.getDate(); month = today.getMonth(); year = today.getFullYear(); m = month+1; y = year; if(m<3) { y -= 1; m += 12; } a = Math.floor(y/100.); b = 2-a+Math.floor(a/4.); if(y<1583) b = 0;

How do I get the AM/PM value from a DateTime?

隐身守侯 提交于 2019-11-26 21:57:24
The code in question is below: public static string ChangePersianDate(DateTime dateTime) { System.Globalization.GregorianCalendar PC = new System.Globalization.GregorianCalendar(); PC.CalendarType = System.Globalization.GregorianCalendarTypes.USEnglish; return PC.GetYear(dateTime).ToString() + "/" + PC.GetMonth(dateTime).ToString() + "/" + PC.GetDayOfMonth(dateTime).ToString() + "" + PC.GetHour(dateTime).ToString() + ":" + PC.GetMinute(dateTime).ToString() + ":" + PC.GetSecond(dateTime).ToString() + " " ???????????????? } how can I get the AM/PM from the dateTime value? How about: dateTime

Get day of the week from GregorianCalendar

旧街凉风 提交于 2019-11-26 21:29:59
问题 I have a date and I need to know the day of the week, so I used a GregorianCalendar object but I get back some dates that are incorrect. GregorianCalendar calendar = new GregorianCalendar(year, month, day); int i = calendar.get(Calendar.DAY_OF_WEEK); What am I doing wrong? Thanks! EDIT SOLUTION: mont--; GregorianCalendar calendar = new GregorianCalendar(year, month, day); int i = calendar.get(Calendar.DAY_OF_WEEK); if(i == 2){ dayOfTheWeek = "Mon"; } else if (i==3){ dayOfTheWeek = "Tue"; }

Specify the date format in XMLGregorianCalendar

霸气de小男生 提交于 2019-11-26 20:25:42
问题 I want to use a Date in XMLGregorianCalendar format for sending to a web service. The web service expects information in yyyy-dd-mm format. I use the below code to create an XMLGregorianCalendar and send it to web service. Date dob = null; DateFormat df = new SimpleDateFormat("dd/MM/yyyy"); try { XMLGregorianCalendar date2; dob = df.parse("13/06/1983"); GregorianCalendar c = new GregorianCalendar(); c.setTimeInMillis(dob.getTime()); date2 = DatatypeFactory.newInstance()

Simple conversion between java.util.Date and XMLGregorianCalendar

不羁岁月 提交于 2019-11-26 17:54:23
问题 I'm looking for a simple method of converting between java.util.Date and javax.xml.datatype.XMLGregorianCalendar in both directions. Here is the code that I'm using now : import java.util.GregorianCalendar; import javax.xml.datatype.DatatypeConfigurationException; import javax.xml.datatype.DatatypeFactory; import javax.xml.datatype.XMLGregorianCalendar; /** * Utility class for converting between XMLGregorianCalendar and java.util.Date */ public class XMLGregorianCalendarConverter { /** *

Using GregorianCalendar with SimpleDateFormat

孤街浪徒 提交于 2019-11-26 16:22:23
问题 So, I've been racking my brain over this (should-be) simple exercise to make the program turn a date string into a GregorianCalendar object, format it, and return it again as a string when it's done. This is the last little bit of a program that takes in a chuck of text from a file, breaks it down into individual records, then breaks the records into individual pieces of data and assigns them to a person object. I've checked the code in multiple places and the code does exactly what it's