Java Code Examples for org.joda.time.DateTime#getDayOfMonth()

The following examples show how to use org.joda.time.DateTime#getDayOfMonth() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
@Override
public String toNonNullValue(DateTime value) {

    DateTimeZone correctTimeZone = value.getZone();
    DateTime utcDateTime = value.withZone(DateTimeZone.UTC);
    DateTime utcDateTimeWithCorrectTimeZone = utcDateTime.withZoneRetainFields(correctTimeZone);
    
    int dayOfMonth = utcDateTimeWithCorrectTimeZone.getDayOfMonth();
    
    String dateTimeAsString = DATE_TIME_PRINTER_PREFIX.print(utcDateTimeWithCorrectTimeZone);
    
    if (dayOfMonth < 10) {
    	dateTimeAsString = dateTimeAsString + "0";
    }
    dateTimeAsString = dateTimeAsString + dayOfMonth;
    
    dateTimeAsString = dateTimeAsString + DATE_TIME_PRINTER_SUFFIX.print(utcDateTimeWithCorrectTimeZone);
    
    return dateTimeAsString;
}
 
Example 2
public static DateTime determineSunsetTimes(DateTime StartTime, double latitude, double longitude,
		String timeZoneId) {
	// Because giving a date with a specific hour could result into getting the
	// sunrise of the previous day,
	// we adjust the date to the beginning of the day
	DateTime beginningOfDay = new DateTime(StartTime.getYear(), StartTime.getMonthOfYear(),
			StartTime.getDayOfMonth(), 0, 0, DateTimeZone.forTimeZone(TimeZone.getTimeZone(timeZoneId)));

	SunTimes times = SunTimes.compute().on(beginningOfDay.toDate()).at(latitude, longitude).execute();

	DateTime sunsetTime = new DateTime(times.getSet())
			.withZone(DateTimeZone.forTimeZone(TimeZone.getTimeZone(timeZoneId)));
	return sunsetTime;

}
 
Example 3
Source Project: BS-Weather   File: Time.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 输入时间 XXXX-XX-XX 的字符串, 放回中文指代的时间, 比如 "今天 02/09"
 */
public static String parseTime(String timeText){
    DateTime dateTime = new DateTime();
    String[] time = timeText.split("-");

    int currentMonth = dateTime.getMonthOfYear();
    int currentDay = dateTime.getDayOfMonth();
    int currentWeak = dateTime.getDayOfWeek();
    int currentYear = dateTime.getYear();

    int month = Integer.parseInt(time[1]);
    int day = Integer.parseInt(time[2]);
    int year = Integer.parseInt(time[0]);

    int offset = 0;  // 相差量

    if (year == currentYear){
        //如果是同一年:
        if (month == currentMonth){
            // 如果是同一个月
            offset = day - currentDay;

        }else{
            offset = day + parseMonth(currentMonth, currentYear) - currentDay;
        }

    }else{
        offset = 31 - currentDay + day;
    }



    String monthAndDay = time[1] + "/" + time[2];
    if (offset == 0) return "今天 " + monthAndDay;
    if (offset == 1) return  "明天 " + monthAndDay;
    return parseWeak(currentWeak + offset) + " " + monthAndDay;

}
 
Example 4
private String getCurrentStreamUri() {
	// Add partition
	DateTime now = new DateTime();
	int monthOfYear = now.getMonthOfYear();
	int dayOfMonth = now.getDayOfMonth();
	int hourOfDay = now.getHourOfDay();
	String year = String.valueOf(now.getYear());
	String month = monthOfYear < 10 ? "0" + String.valueOf(monthOfYear)
			: String.valueOf(monthOfYear);
	String day = dayOfMonth < 10 ? "0" + String.valueOf(dayOfMonth)
			: String.valueOf(dayOfMonth);
	String hour = hourOfDay < 10 ? "0" + String.valueOf(hourOfDay) : String
			.valueOf(hourOfDay);
	return "/" + year + "/" + month + "/" + day + "/" + hour;
}
 
Example 5
public GetTherapeuticLinkResponse mapXMLToGetTherapeuticLinkResponse(String xml) throws TechnicalConnectorException {
   be.fgov.ehealth.hubservices.core.v2.GetTherapeuticLinkResponse jaxbResponse = (be.fgov.ehealth.hubservices.core.v2.GetTherapeuticLinkResponse)this.generateJAXB(xml, be.fgov.ehealth.hubservices.core.v2.GetTherapeuticLinkResponse.class);
   ResponseType jaxbResponseType = jaxbResponse.getResponse();
   DateTime date = jaxbResponseType.getDate();
   DateTime time = jaxbResponseType.getTime();
   DateTime dateTime = new DateTime(date.getYear(), date.getMonthOfYear(), date.getDayOfMonth(), time.getHourOfDay(), time.getMinuteOfHour(), time.getSecondOfMinute(), time.getMillisOfSecond());
   GetTherapeuticLinkResponse response = new GetTherapeuticLinkResponse(dateTime, this.mapAuthor(jaxbResponseType.getAuthor()), jaxbResponseType.getId().getValue(), this.mapOriginalGetTherapeuticLinkRequest(jaxbResponseType.getRequest()), this.mapListOfTherapeuticLinks(jaxbResponse.getTherapeuticlinklist()), this.mapAcknowledge(jaxbResponse.getAcknowledge()));
   LOG.info("Output request object :" + response.toString());
   return response;
}
 
Example 6
public HasTherapeuticLinkResponse mapXMLToHasTherapeuticLinkResponse(String xml) throws TechnicalConnectorException {
   be.fgov.ehealth.hubservices.core.v2.HasTherapeuticLinkResponse jaxbResponse = (be.fgov.ehealth.hubservices.core.v2.HasTherapeuticLinkResponse)this.generateJAXB(xml, be.fgov.ehealth.hubservices.core.v2.HasTherapeuticLinkResponse.class);
   ResponseType jaxbResponseType = jaxbResponse.getResponse();
   DateTime date = jaxbResponseType.getDate();
   DateTime time = jaxbResponseType.getTime();
   DateTime dateTime = new DateTime(date.getYear(), date.getMonthOfYear(), date.getDayOfMonth(), time.getHourOfDay(), time.getMinuteOfHour(), time.getSecondOfMinute(), time.getMillisOfSecond());
   HasTherapeuticLinkResponse response = new HasTherapeuticLinkResponse(dateTime, this.mapAuthor(jaxbResponseType.getAuthor()), jaxbResponseType.getId().getValue(), this.mapOriginalHasTherapeuticLinkRequest(jaxbResponseType.getRequest()), this.mapAcknowledge(jaxbResponse.getAcknowledge()));
   LOG.info("Output request object :" + response.toString());
   return response;
}
 
Example 7
Source Project: foxtrot   File: Date.java    License: Apache License 2.0 5 votes vote down vote up
public Date(DateTime dateTime) {

        this.year = dateTime.getYear();
        this.monthOfYear = dateTime.getMonthOfYear();
        this.dayOfWeek = dateTime.getDayOfWeek();
        this.dayOfMonth = dateTime.getDayOfMonth();
        this.hourOfDay = dateTime.getHourOfDay();
        this.minuteOfHour = dateTime.getMinuteOfHour();
        this.minuteOfDay = dateTime.getMinuteOfDay();
        this.weekOfYear = dateTime.getWeekOfWeekyear();
    }
 
Example 8
private DateTime mapDateTime(DateTime date, DateTime time) {
   return new DateTime(date != null ? date.getYear() : 0, date != null ? date.getMonthOfYear() : 1, date != null ? date.getDayOfMonth() : 1, time.getHourOfDay(), time.getMinuteOfHour(), time.getSecondOfMinute(), time.getMillisOfSecond(), DateTimeZone.getDefault());
}
 
Example 9
private TherapeuticLinkRequestType mapOriginalPutTherapeuticLinkRequest(RequestType request) {
   DateTime date = request.getDate();
   DateTime time = request.getTime();
   DateTime dateTime = new DateTime(date.getYear(), date.getMonthOfYear(), date.getDayOfMonth(), time.getHourOfDay(), time.getMinuteOfHour(), time.getSecondOfMinute(), time.getMillisOfSecond());
   return new PutTherapeuticLinkRequest(dateTime, request.getId().getValue(), this.mapAuthor((AuthorType)request.getAuthor()));
}
 
Example 10
Source Project: maven-framework-project   File: Jodatime.java    License: MIT License 4 votes vote down vote up
private static void getTimeInfo(){
	
	System.out.println("-------------获取当前时间-----------------");
	
	String weekStr="";
	
	DateTime dt = new DateTime();
	//年
	int year = dt.getYear();
	//月
	int month = dt.getMonthOfYear();
	//日
	int day = dt.getDayOfMonth();
	//星期
	int week = dt.getDayOfWeek();
	//点
	int hour = dt.getHourOfDay();
	//分
	int min = dt.getMinuteOfHour();
	//秒
	int sec = dt.getSecondOfMinute();
	//毫秒
	int msec = dt.getMillisOfSecond();
	
	//星期
	switch(week) {
	case DateTimeConstants.SUNDAY:
		weekStr = "星期日";
		System.out.println(weekStr);
		break;
	case DateTimeConstants.MONDAY:
		weekStr = "星期一";
		System.out.println(weekStr);
		break;
	case DateTimeConstants.TUESDAY:
		weekStr = "星期二";
		System.out.println(weekStr);
		break;
	case DateTimeConstants.WEDNESDAY:
		weekStr = "星期三";
		System.out.println(weekStr);
		break;
	case DateTimeConstants.THURSDAY:
		weekStr = "星期四";
		System.out.println(weekStr);
		break;
	case DateTimeConstants.FRIDAY:
		weekStr = "星期五";
		System.out.println(weekStr);
		break;
	case DateTimeConstants.SATURDAY:
		weekStr = "星期六";
		System.out.println(weekStr);
		break;
	}
	
	System.out.println(year + "/" + month + "/" + day + " " + hour + ":" + min + ":" + sec + ":" + msec + " " + weekStr);
	
}
 
Example 11
private DateTime mapDateTime(DateTime date, DateTime time) {
   return new DateTime(date != null ? date.getYear() : 0, date != null ? date.getMonthOfYear() : 1, date != null ? date.getDayOfMonth() : 1, time.getHourOfDay(), time.getMinuteOfHour(), time.getSecondOfMinute(), time.getMillisOfSecond(), DateTimeZone.getDefault());
}
 
Example 12
private DateTime mapDateTime(DateTime date, DateTime time) {
   return new DateTime(date != null ? date.getYear() : 0, date != null ? date.getMonthOfYear() : 1, date != null ? date.getDayOfMonth() : 1, time.getHourOfDay(), time.getMinuteOfHour(), time.getSecondOfMinute(), time.getMillisOfSecond(), DateTimeZone.getDefault());
}
 
Example 13
Source Project: jianshi   File: FullDateManager.java    License: Apache License 2.0 4 votes vote down vote up
public static long getTodayDateSeconds() {
  DateTime now = new DateTime();
  // clear info about hours and seconds, only need year, month and day.
  DateTime today = new DateTime(now.getYear(), now.getMonthOfYear(), now.getDayOfMonth(), 0, 0);
  return today.getMillis() / 1000;
}
 
Example 14
Source Project: jianshi   File: FullDateManager.java    License: Apache License 2.0 4 votes vote down vote up
public FullDateManager(long dateSeconds) {
  DateTime dateTime = getDateTime(dateSeconds);
  this.year = dateTime.getYear();
  this.month = dateTime.getMonthOfYear();
  this.day = dateTime.getDayOfMonth();
}
 
Example 15
private TherapeuticLinkRequestType mapOriginalRevokeTherapeuticLinkRequest(RequestType request) {
   DateTime date = request.getDate();
   DateTime time = request.getTime();
   DateTime dateTime = new DateTime(date.getYear(), date.getMonthOfYear(), date.getDayOfMonth(), time.getHourOfDay(), time.getMinuteOfHour(), time.getSecondOfMinute(), time.getMillisOfSecond());
   return new RevokeTherapeuticLinkRequest(dateTime, request.getId().getValue(), this.mapAuthor(request.getAuthor()), (TherapeuticLink)null, (Proof[])null);
}
 
Example 16
private void submitWorkflowJob(String workFlowRoot)
		throws OozieClientException, InterruptedException {
	String oozieURL = System.getProperty("oozie.base.url");
	LOG.debug("Oozie BaseURL is: {} ", oozieURL);
	OozieClient client = new OozieClient(oozieURL);

	DateTime now = new DateTime();
	int monthOfYear = now.getMonthOfYear();
	int dayOfMonth = now.getDayOfMonth();
	int hourOfDay = now.getHourOfDay();
	String year = String.valueOf(now.getYear());
	String month = monthOfYear < 10 ? "0" + String.valueOf(monthOfYear)
			: String.valueOf(monthOfYear);
	String day = dayOfMonth < 10 ? "0" + String.valueOf(dayOfMonth)
			: String.valueOf(dayOfMonth);
	String hour = hourOfDay < 10 ? "0" + String.valueOf(hourOfDay) : String
			.valueOf(hourOfDay);

	Properties conf = client.createConfiguration();
	conf.setProperty(OozieClient.APP_PATH, workFlowRoot
			+ "/hive-action-add-partition.xml");
	conf.setProperty("nameNode", hadoopClusterService.getHDFSUri());
	conf.setProperty("jobTracker", hadoopClusterService.getJobTRackerUri());
	conf.setProperty("workflowRoot", workFlowRoot);
	conf.setProperty("YEAR", year);
	conf.setProperty("MONTH", month);
	conf.setProperty("DAY", day);
	conf.setProperty("HOUR", hour);
	conf.setProperty("oozie.use.system.libpath", "true");

	// submit and start the workflow job
	client.setDebugMode(1);
	// client.dryrun(conf);
	String jobId = client.run(conf);// submit(conf);

	LOG.debug("Workflow job submitted");
	// wait until the workflow job finishes printing the status every 10
	// seconds
	int retries = 3;
	for (int i = 1; i <= retries; i++) {
		// Sleep 60 sec./ 3 mins
		Thread.sleep(60 * 1000);

		WorkflowJob jobInfo = client.getJobInfo(jobId);
		Status jobStatus = jobInfo.getStatus();
		LOG.debug("Workflow job running ...");
		LOG.debug("HiveActionWorkflowJob Status Try: {}", i);
		LOG.debug("HiveActionWorkflowJob Id: {}", jobInfo.getId());
		LOG.debug("HiveActionWorkflowJob StartTime: {}",
				jobInfo.getStartTime());
		LOG.debug("HiveActionWorkflowJob EndTime: {}", jobInfo.getEndTime());
		LOG.debug("HiveActionWorkflowJob ConsoleURL: {}",
				jobInfo.getConsoleUrl());
		LOG.debug("HiveActionWorkflowJob Status: {}", jobInfo.getStatus());

		WorkflowAction workflowAction = jobInfo.getActions().get(0);

		LOG.debug("HiveActionWorkflowJob Action consoleURL: {}",
				workflowAction.getConsoleUrl());
		LOG.debug("HiveActionWorkflowJob Action Name: {}",
				workflowAction.getName());
		LOG.debug("HiveActionWorkflowJob Action error message: {}",
				workflowAction.getErrorMessage());
		LOG.debug("HiveActionWorkflowJob Action Status: {}",
				workflowAction.getStats());
		LOG.debug("HiveActionWorkflowJob Action data: {}",
				workflowAction.getData());
		LOG.debug("HiveActionWorkflowJob Action conf: {}",
				workflowAction.getConf());
		LOG.debug("HiveActionWorkflowJob Action retries: {}",
				workflowAction.getRetries());
		LOG.debug("HiveActionWorkflowJob Action id: {}",
				workflowAction.getId());
		LOG.debug("HiveActionWorkflowJob Action start time: {}",
				workflowAction.getStartTime());
		LOG.debug("HiveActionWorkflowJob Action end time: {}",
				workflowAction.getEndTime());
		LOG.debug("HiveActionWorkflowJob Oozie Url: {}",
				client.getOozieUrl());

		if (jobStatus == WorkflowJob.Status.SUCCEEDED) {
			LOG.info("Oozie workflow job was successful!" + jobStatus);
			break;
		} else if (jobStatus == WorkflowJob.Status.PREP
				|| jobStatus == WorkflowJob.Status.RUNNING) {
			if (i == retries) {
				throw new RuntimeException("Error executing workflow job!"
						+ jobStatus);
			} else {
				continue;
			}
		} else {
			throw new RuntimeException("Error executing workflow job!"
					+ jobStatus);
		}
	}
}
 
Example 17
/**
 * Null-safe method that returns a new instance of a DateTime object rounded
 * downwards to the nearest day. The time zone of the returned DateTime
 * instance will be the same as the argument. Similar to a floor() function
 * on a float.<br>
 * Examples:
 * <ul>
 *      <li>null -> null
 *      <li>"2009-06-24 13:24:51.476 -8:00" -> "2009-06-24 00:00:00.000 -8:00"
 * </ul>
 * @param value The DateTime value to round downward
 * @return Null if the argument is null or a new instance of the DateTime
 *      value rounded downwards to the nearest day.
 */
public static DateTime floorToDay(DateTime value) {
    if (value == null) {
        return null;
    }
    return new DateTime(value.getYear(), value.getMonthOfYear(), value.getDayOfMonth(), 0, 0, 0, 0, value.getZone());
}
 
Example 18
Source Project: Mycat2   File: DateUtil.java    License: GNU General Public License v3.0 2 votes vote down vote up
/**
 * 获取date对象天数
 * @param date
 * @return
 */
public static int getDay(Date date) {
	DateTime dt = new DateTime(date);
	return dt.getDayOfMonth();
}
 
Example 19
Source Project: dble   File: DateUtil.java    License: GNU General Public License v2.0 2 votes vote down vote up
/**
 * getDay
 *
 * @param date
 * @return
 */
public static int getDay(Date date) {
    DateTime dt = new DateTime(date);
    return dt.getDayOfMonth();
}
 
Example 20
Source Project: Mycat2   File: DateUtil.java    License: GNU General Public License v3.0 2 votes vote down vote up
/**
 * 获取date对象天数
 * @param date
 * @return
 */
public static int getDay(Date date) {
	DateTime dt = new DateTime(date);
	return dt.getDayOfMonth();
}