Example usage for java.util Calendar HOUR

List of usage examples for java.util Calendar HOUR

Introduction

In this page you can find the example usage for java.util Calendar HOUR.

Prototype

int HOUR

To view the source code for java.util Calendar HOUR.

Click Source Link

Document

Field number for get and set indicating the hour of the morning or afternoon.

Usage

From source file:com.eryansky.common.utils.DateUtil.java

/**
 * Calendar?/*from  w ww .jav  a  2  s  .c  o m*/
 */
public static long getLongTime(Calendar yourCalendar) {
    try {
        long longCalendar = 0;
        // 
        String strYear = String.valueOf(yourCalendar.get(Calendar.YEAR));
        String strMonth = String.valueOf(yourCalendar.get(Calendar.MONTH) + 1);
        String strDate = String.valueOf(yourCalendar.get(Calendar.DATE));
        String strHour = String.valueOf(yourCalendar.get(Calendar.HOUR));
        String strAM_PM = String.valueOf(yourCalendar.get(Calendar.AM_PM));
        String strMinute = String.valueOf(yourCalendar.get(Calendar.MINUTE));
        String strSecond = String.valueOf(yourCalendar.get(Calendar.SECOND));

        // ?24?
        // strAM_PM=="1",??strHour?12
        if (strAM_PM.equals("1")) {
            strHour = String.valueOf(Long.parseLong(strHour) + 12);
        }

        // ??
        if (strMonth.length() < 2) {
            strMonth = "0" + strMonth;
        }
        if (strDate.length() < 2) {
            strDate = "0" + strDate;
        }
        if (strHour.length() < 2) {
            strHour = "0" + strHour;
        }
        if (strMinute.length() < 2) {
            strMinute = "0" + strMinute;
        }
        if (strSecond.length() < 2) {
            strSecond = "0" + strSecond;
        }
        // ?
        longCalendar = Long.parseLong(strYear + strMonth + strDate + strHour + strMinute + strSecond);

        // ?
        return longCalendar;
    } catch (Exception Exp) {
        return 0;
    }
}

From source file:net.navasoft.madcoin.backend.services.rest.impl.OrdersService.java

/**
 * Gets the available requests by segment.
 * //from w ww . j a v a 2 s .  c o  m
 * @param userType
 *            the user type
 * @param business_line
 *            the business_line
 * @param service_category
 *            the service_category
 * @param filter
 *            the filter
 * @return the available requests by segment
 * @since 31/08/2014, 02:50:04 PM
 */
@Override
public WorkRequestListVO getAvailableRequestsBySegment(String userType, String business_line,
        String service_category, IFilteredFields<?, ?, ?> filter) {
    WorkRequestListVO list = new WorkRequestListVO();
    int orderAmount = Calendar.getInstance().get(Calendar.HOUR);
    do {
        WorkRequestVO order = new WorkRequestVO();
        order.setRequestIdentifier(
                MessageFormat.format("{0}-{1}-{2}", business_line, service_category, orderAmount));
        order.setCategory(business_line);
        order.setSubCategory(service_category);
        order.setOrderLocation("Carrera 26 # 27A - 13 Sur");
        order.setOrderLocationDetails("Click -n- Done CTO - Master Developer");
        order.setUsernameRequester("jnavarre");
        Calendar orderDate = Calendar.getInstance();
        orderDate.add(Calendar.HOUR, -orderAmount);
        order.setOrderGeneration(orderDate.getTime());
        order.setOrderStatus(orderDate.get(Calendar.HOUR_OF_DAY) % 2 == 0 ? OrderStatus.ASSIGNED_BY_ADMIN
                : OrderStatus.CANCELLED_BY_USER);
        order.setOrderSummary("Asking for Blowjob...");
        list.addWorkRequest(order);
        orderAmount--;
    } while (orderAmount > 0);
    return list;
}

From source file:com.nest5.businessClient.Initialactivity.java

/**
 * Begins the activity.//from ww w .ja va2  s. c o m
 */
@Override
public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    this.savedInstanceState = savedInstanceState;
    getWindow().setFormat(PixelFormat.RGBA_8888);
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_DITHER);
    BugSenseHandler.initAndStartSession(Initialactivity.this, "1a5a6af1");
    setContentView(R.layout.swipe_view);
    checkLogin();
    // add necessary intent values to be matched.

    intentFilter.addAction(WifiP2pManager.WIFI_P2P_STATE_CHANGED_ACTION);
    intentFilter.addAction(WifiP2pManager.WIFI_P2P_PEERS_CHANGED_ACTION);
    intentFilter.addAction(WifiP2pManager.WIFI_P2P_CONNECTION_CHANGED_ACTION);
    intentFilter.addAction(WifiP2pManager.WIFI_P2P_THIS_DEVICE_CHANGED_ACTION);

    manager = (WifiP2pManager) getSystemService(Context.WIFI_P2P_SERVICE);
    channel = manager.initialize(this, getMainLooper(), null);
    mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
    dbHelper = new MySQLiteHelper(this);
    ingredientCategoryDatasource = new IngredientCategoryDataSource(dbHelper);
    db = ingredientCategoryDatasource.open();
    ingredientCategories = ingredientCategoryDatasource.getAllIngredientCategory();
    // ingredientCategoryDatasource.close();
    productCategoryDatasource = new ProductCategoryDataSource(dbHelper);
    productCategoryDatasource.open(db);
    productsCategories = productCategoryDatasource.getAllProductCategory();
    taxDataSource = new TaxDataSource(dbHelper);
    taxDataSource.open(db);
    taxes = taxDataSource.getAllTax();
    unitDataSource = new UnitDataSource(dbHelper);
    unitDataSource.open(db);
    units = unitDataSource.getAllUnits();
    ingredientDatasource = new IngredientDataSource(dbHelper);
    ingredientDatasource.open(db);
    ingredientes = ingredientDatasource.getAllIngredient();
    productDatasource = new ProductDataSource(dbHelper);
    productDatasource.open(db);
    productos = productDatasource.getAllProduct();
    comboDatasource = new ComboDataSource(dbHelper);
    comboDatasource.open(db);
    combos = comboDatasource.getAllCombos();
    saleDataSource = new SaleDataSource(dbHelper);
    saleDataSource.open(db);
    saleList = saleDataSource.getAllSales();
    syncRowDataSource = new SyncRowDataSource(dbHelper);
    syncRowDataSource.open(db);

    Calendar today = Calendar.getInstance();
    Calendar tomorrow = Calendar.getInstance();
    today.set(Calendar.HOUR, 0);
    today.set(Calendar.HOUR_OF_DAY, 0);
    today.set(Calendar.MINUTE, 0);
    today.set(Calendar.SECOND, 0);
    today.set(Calendar.MILLISECOND, 0);
    tomorrow.roll(Calendar.DATE, 1);
    tomorrow.set(Calendar.HOUR, 0);
    tomorrow.set(Calendar.HOUR_OF_DAY, 0);
    tomorrow.set(Calendar.MINUTE, 0);
    tomorrow.set(Calendar.SECOND, 0);
    tomorrow.set(Calendar.MILLISECOND, 0);

    init = today.getTimeInMillis();
    end = tomorrow.getTimeInMillis();
    //Log.d(TAG, today.toString());
    //Log.d(TAG, tomorrow.toString());
    Calendar now = Calendar.getInstance();
    now.setTimeInMillis(System.currentTimeMillis());
    //Log.d(TAG, now.toString());

    //Log.d(TAG, "Diferencia entre tiempos: " + String.valueOf(end - init));
    salesFromToday = saleDataSource.getAllSalesWithin(init, end);
    updateRegistrables();
    // ingredientDatasource.close();
    mDemoCollectionPagerAdapter = new DemoCollectionPagerAdapter(getSupportFragmentManager());
    mViewPager = (ViewPager) findViewById(R.id.pager);
    mViewPager.setAdapter(mDemoCollectionPagerAdapter);

    mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
        @Override
        public void onPageSelected(int position) {
            // When swiping between pages, select the
            // corresponding tab.
            getActionBar().setSelectedNavigationItem(position);

        }
    });

    final ActionBar actionBar = getActionBar();
    // Specify that tabs should be displayed in the action bar.
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

    // Create a tab listener that is called when the user changes tabs.
    ActionBar.TabListener tabListener = new ActionBar.TabListener() {

        @Override
        public void onTabReselected(Tab tab, FragmentTransaction ft) {
            // TODO Auto-generated method stub

        }

        @Override
        public void onTabSelected(Tab tab, FragmentTransaction ft) {
            mViewPager.setCurrentItem(tab.getPosition());

        }

        @Override
        public void onTabUnselected(Tab tab, FragmentTransaction ft) {
            // TODO Auto-generated method stub

        }

    };

    Tab homeTab = actionBar.newTab().setText("Inicio").setTabListener(tabListener);
    Tab ordersTab = actionBar.newTab().setText("rdenes").setTabListener(tabListener);
    /*Tab dailyTab = actionBar.newTab().setText("Registros")
    .setTabListener(tabListener);
    Tab inventoryTab = actionBar.newTab().setText("Inventarios")
    .setTabListener(tabListener);*/
    Tab nest5ReadTab = actionBar.newTab().setText("Nest5").setTabListener(tabListener);
    actionBar.addTab(homeTab, true);
    actionBar.addTab(ordersTab, false);
    //actionBar.addTab(dailyTab, false);
    //actionBar.addTab(inventoryTab, false);
    actionBar.addTab(nest5ReadTab, false);

    currentOrder = new LinkedHashMap<Registrable, Integer>();
    inTableRegistrable = new ArrayList<Registrable>();
    savedOrders = new LinkedHashMap<String, LinkedHashMap<Registrable, Integer>>();
    cookingOrders = new LinkedList<LinkedHashMap<Registrable, Integer>>();
    //cookingOrdersMethods = new LinkedHashMap<LinkedHashMap<Registrable, Integer>, String>();
    cookingOrdersDelivery = new LinkedHashMap<LinkedHashMap<Registrable, Integer>, Integer>();
    cookingOrdersTogo = new LinkedHashMap<LinkedHashMap<Registrable, Integer>, Integer>();
    //cookingOrdersTip = new LinkedHashMap<LinkedHashMap<Registrable, Integer>, Integer>();
    //cookingOrdersDiscount = new LinkedHashMap<LinkedHashMap<Registrable, Integer>, Double>();
    cookingOrdersTimes = new LinkedHashMap<LinkedHashMap<Registrable, Integer>, Long>();
    cookingOrdersTable = new LinkedHashMap<LinkedHashMap<Registrable, Integer>, CurrentTable<Table, Integer>>();
    openTables = new LinkedList<CurrentTable<Table, Integer>>();
    //cookingOrdersReceived = new LinkedHashMap<LinkedHashMap<Registrable, Integer>, Double>();
    frases = getResources().getStringArray(R.array.phrases);
    timer = new Timer();
    deviceID = DeviceID.getDeviceId(mContext);
    //////Log.i("AACCCAAAID",deviceID);
    BebasFont = Typeface.createFromAsset(getAssets(), "fonts/BebasNeue.otf");
    VarelaFont = Typeface.createFromAsset(getAssets(), "fonts/Varela-Regular.otf");
    // Lector de tarjetas magnticas
    mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
    //mReader = new ACR31Reader(mAudioManager);
    /* Initialize the reset progress dialog */

    mResetProgressDialog = new ProgressDialog(mContext);

    // ACR31 RESET CALLBACK
    /*mReader.setOnResetCompleteListener(new ACR31Reader.OnResetCompleteListener() {
            
               
       //hola como estas
       @Override
       public void onResetComplete(ACR31Reader reader) {
            
    if (mSettingSleepTimeout) {
            
            
       mGettingStatus = true;
            
            
       mReader.setSleepTimeout(mSleepTimeout);
       mSettingSleepTimeout = false;
    }
            
    runOnUiThread(new Runnable() {
            
       @Override
       public void run() {
          mResetProgressDialog.dismiss();
       };
    });
       }
    });*/
    /* Set the raw data callback. */
    /*mReader.setOnRawDataAvailableListener(new ACR31Reader.OnRawDataAvailableListener() {
            
       @Override
       public void onRawDataAvailable(ACR31Reader reader, byte[] rawData) {
    ////Log.i("MISPRUEBAS", "setOnRawDataAvailableListener");
            
    final String hexString = toHexString(rawData)
          + (reader.verifyData(rawData) ? " (Checksum OK)"
                : " (Checksum Error)");
            
    ////Log.i("MISPRUEBAS", hexString);
    if (reader.verifyData(rawData)) {
       runOnUiThread(new Runnable() {
            
          @Override
          public void run() {
            
             mResetProgressDialog
                   .setMessage("Solicitando Informacin al Servidor...");
             mResetProgressDialog.setCancelable(false);
             mResetProgressDialog.setIndeterminate(true);
             mResetProgressDialog.show();
            
          }
       });
       SharedPreferences prefs = Util
             .getSharedPreferences(mContext);
            
       restService = new RestService(recievePromoandUserHandler,
             mContext, Setup.PROD_URL
                   + "/company/initMagneticStamp");
       restService.addParam("company",
             prefs.getString(Setup.COMPANY_ID, "0"));
       restService.addParam("magnetic5", hexString);
       restService.setCredentials("apiadmin", Setup.apiKey);
       try {
          restService.execute(RestService.POST);
       } catch (Exception e) {
          e.printStackTrace();
          ////Log.i("MISPRUEBAS", "Error empezando request");
       }
    }
            
       }
    });*/

}

From source file:ezbake.data.elastic.ElasticClientTest.java

@Test
public void testQueryRangeDateNoMapping() throws Exception {
    client.setTypeMapping(TEST_TYPE, "");

    final Calendar now = new GregorianCalendar();
    now.add(Calendar.HOUR, -1);
    final Long oneHourAgo = now.getTimeInMillis();
    now.add(Calendar.HOUR, 25);/*from www .ja v a  2  s  .c  o m*/
    final Long oneDayFromNow = now.getTimeInMillis();

    final String dateRangeQuery = QueryBuilders.rangeQuery("visit").gt(oneHourAgo).lt(oneDayFromNow).toString();
    final SearchResult results = client.get(dateRangeQuery, TEST_TYPE, null, null, null, null, 0, (short) -1,
            null, COMMON_USER_TOKEN);

    assertEquals(0, results.getTotalHits());
}

From source file:br.org.indt.ndg.server.instance.SystemPropertiesInstance.java

public static String toDate(Date d) {
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(d);//from   w  ww.  j  ava  2 s.  co m
    String fieldDate = calendar.get(Calendar.DAY_OF_MONTH) + "/" + (calendar.get(Calendar.MONTH) + 1) + "/"
            + calendar.get(Calendar.YEAR) + " " + calendar.get(Calendar.HOUR) + ":"
            + calendar.get(Calendar.MINUTE) + ":" + calendar.get(Calendar.SECOND);
    return fieldDate;
}

From source file:ezbake.data.elastic.ElasticClientTest.java

@Test
public void testQueryRangeDateMapped() throws Exception {
    final SimpleDateFormat dtg = new SimpleDateFormat(EzElasticTestUtils.DATE_FORMAT);
    final Calendar now = Calendar.getInstance();
    now.add(Calendar.HOUR, 1);
    final Date oneHourFromNow = now.getTime();
    now.add(Calendar.DAY_OF_MONTH, -1);
    final Date oneDayAgo = now.getTime();

    final String dateRangeQuery = QueryBuilders.rangeQuery("visit").gt(dtg.format(oneDayAgo))
            .lt(dtg.format(oneHourFromNow)).toString();

    final SearchResult resultsCommonVis = client.get(dateRangeQuery, TEST_TYPE, null, null, null, null, 0,
            (short) -1, null, COMMON_USER_TOKEN);

    assertEquals(/*  w  w w.j ava  2s. c  o  m*/
            Sets.newHashSet(columbiaDoc.get_id(), lincolnMemorialDoc.get_id(), jeffersonMemorialDoc.get_id()),
            docListToIdsSet(resultsCommonVis.getMatchingDocuments()));

    final SearchResult resultsVis1 = client.get(dateRangeQuery, TEST_TYPE, null, null, null, null, 0,
            (short) -1, null, TestUtils.createTestToken("A", "B", "C"));

    assertEquals(
            Sets.newHashSet(columbiaDoc.get_id(), lincolnMemorialDoc.get_id(), jeffersonMemorialDoc.get_id(),
                    lincolnMemorialDocWithVis.get_id(), jeffersonMemorialDocWithVis.get_id()),
            docListToIdsSet(resultsVis1.getMatchingDocuments()));

    final SearchResult resultsVis2 = client.get(dateRangeQuery, TEST_TYPE, null, null, null, null, 0,
            (short) -1, null, TestUtils.createTestToken("A", "B", "E"));

    assertEquals(
            Sets.newHashSet(columbiaDoc.get_id(), lincolnMemorialDoc.get_id(), jeffersonMemorialDoc.get_id(),
                    columbiaDocWithVis.get_id(), lincolnMemorialDocWithVis.get_id()),
            docListToIdsSet(resultsVis2.getMatchingDocuments()));
}

From source file:com.ecofactor.qa.automation.api.ReportsAPITest.java

/**
 * Location savings./*from  ww w. ja v a2s .co m*/
 */
@Test(groups = { "sanity1" })
public void locationSavings() {

    String id = reportsAPIConfig.get(ReportsAPIConfig.LOCATION_ID);
    String content = HttpUtil.get(getLocationSavingsURL(id), getNotAccumulatedParams(5), 200);
    JSONObject object = JsonUtil.parseObject(content);

    Calendar start = DateUtil.getUTCCalendar();
    start.set(Calendar.MONTH, 5 - 1);
    start.set(Calendar.DATE, 1);
    start.set(Calendar.HOUR, 0);
    start.set(Calendar.MINUTE, 0);
    start.set(Calendar.SECOND, 0);
    Calendar end = DateUtil.getUTCCalendar();
    end.set(Calendar.MONTH, 5 - 1);
    end.set(Calendar.DATE, end.getMaximum(Calendar.DATE));
    end.set(Calendar.HOUR, 23);
    end.set(Calendar.MINUTE, 59);
    end.set(Calendar.SECOND, 0);
    assertLocationSavingsData(object, start, end);
}

From source file:com.ecofactor.qa.automation.api.HttpsReportsAPITest.java

/**
 * Location savings.//from   www  .  j  a  v a2s. co m
 */
@Test(groups = { "sanity1" })
public void locationSavings() {

    String id = reportsAPIConfig.get(HttpsReportsAPIConfig.LOCATION_ID);
    String content = HttpsUtil.get(getLocationSavingsURL(id), getNotAccumulatedParams(5), 200);
    JSONObject object = JsonUtil.parseObject(content);

    Calendar start = DateUtil.getUTCCalendar();
    start.set(Calendar.MONTH, 5 - 1);
    start.set(Calendar.DATE, 1);
    start.set(Calendar.HOUR, 0);
    start.set(Calendar.MINUTE, 0);
    start.set(Calendar.SECOND, 0);
    Calendar end = DateUtil.getUTCCalendar();
    end.set(Calendar.MONTH, 5 - 1);
    end.set(Calendar.DATE, end.getMaximum(Calendar.DATE));
    end.set(Calendar.HOUR, 23);
    end.set(Calendar.MINUTE, 59);
    end.set(Calendar.SECOND, 0);
    assertLocationSavingsData(object, start, end);
}

From source file:jef.tools.DateUtils.java

/**
 *  ?? ?DateDate/*from   w w  w. j  a  v a  2 s .c o m*/
 * 
 * @param date
 *            
 * @param hour
 *            ?
 * @param minute
 *            ?
 * @param second
 *            ?
 * @return ?
 */
public static Date adjustTime(Date date, int hour, int minute, int second) {
    Calendar c = Calendar.getInstance();
    c.setTime(date);
    c.add(Calendar.HOUR, hour);
    c.add(Calendar.MINUTE, minute);
    c.add(Calendar.SECOND, second);
    return c.getTime();
}

From source file:com.xxl.report.service.ReportService.java

private Calendar getNextRunningDate(int type) {
    Calendar cal = Calendar.getInstance();
    switch (type) {
    case SemAppConstants.REPORT_SCHEDULE_ONCE: {
        break;//ww w  . j a va 2s.  c o m
    }
    case SemAppConstants.REPORT_SCHEDULE_HOUR: {
        cal.add(Calendar.HOUR, 1);
        break;
    }
    case SemAppConstants.REPORT_SCHEDULE_WEEK: {
        cal.add(Calendar.WEEK_OF_MONTH, 1);
        break;
    }
    case SemAppConstants.REPORT_SCHEDULE_DAY: {
        cal.add(Calendar.DAY_OF_MONTH, 1);
        break;
    }
    case SemAppConstants.REPORT_SCHEDULE_MONTH: {
        cal.add(Calendar.MONTH, 1);
        break;
    }
    case SemAppConstants.REPORT_SCHEDULE_YEAR: {
        cal.add(Calendar.YEAR, 1);
        break;
    }
    }
    return cal;
}