Example usage for java.util TimeZone getDefault

List of usage examples for java.util TimeZone getDefault

Introduction

In this page you can find the example usage for java.util TimeZone getDefault.

Prototype

public static TimeZone getDefault() 

Source Link

Document

Gets the default TimeZone of the Java virtual machine.

Usage

From source file:com.QuarkLabs.BTCeClient.adapters.OrdersAdapter.java

public OrdersAdapter(Context context, ListType listType) {
    mContext = context;/*www  .  jav a  2s .c  om*/
    mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    mListType = listType;
    mDateFormat.setTimeZone(TimeZone.getDefault());
}

From source file:com.haulmont.cuba.core.sys.querymacro.TimeTodayQueryMacroHandler.java

@Override
protected String doExpand(String macro) {
    count++;//from  www  .  ja  v a 2  s.  co m
    String[] args = macro.split(",");
    if (args.length != 1 && args.length != 2)
        throw new RuntimeException("Invalid macro: " + macro);
    String field = args[0].trim();
    String param1 = field.replace(".", "_") + "_" + count + "_1";
    String param2 = field.replace(".", "_") + "_" + count + "_2";

    TimeZone timeZone = getTimeZoneFromArgs(args, 1);
    if (timeZone == null) {
        timeZone = TimeZone.getDefault();
    }
    Calendar cal = Calendar.getInstance(timeZone);
    cal.setTime(AppBeans.get(TimeSource.class).currentTimestamp());

    params.put(param1, DateUtils.truncate(cal, Calendar.DAY_OF_MONTH).getTime());

    cal.add(Calendar.DAY_OF_MONTH, 1);
    params.put(param2, DateUtils.truncate(cal, Calendar.DAY_OF_MONTH).getTime());

    return String.format("(%s >= :%s and %s < :%s)", field, param1, field, param2);
}

From source file:com.microsoft.exchange.DateHelpTest.java

@Test
public void systemTimeZone() {
    List<String> availableIDs = Arrays.asList(TimeZone.getAvailableIDs());
    assertFalse(CollectionUtils.isEmpty(availableIDs));
    assertTrue(availableIDs.contains(TimeZones.UTC_ID));
    assertTrue(availableIDs.contains("UTC"));

    TimeZone ical4jUTC = TimeZone.getTimeZone(TimeZones.UTC_ID);
    TimeZone sysUTC = TimeZone.getTimeZone("UTC");

    assertEquals(ical4jUTC.getDSTSavings(), sysUTC.getDSTSavings());
    assertEquals(ical4jUTC.getRawOffset(), sysUTC.getRawOffset());
    assertTrue(ical4jUTC.hasSameRules(sysUTC));

    TimeZone origDefaultTimeZone = TimeZone.getDefault();
    assertNotNull(origDefaultTimeZone);//from  w ww . ja v  a  2 s . c  om
    assertEquals(TimeZone.getDefault().getRawOffset(), origDefaultTimeZone.getRawOffset());

    log.info("TimeZone.DisplayName=" + origDefaultTimeZone.getDisplayName());
    log.info("TimeZone.ID=" + origDefaultTimeZone.getID());
    log.info("TimeZone.DSTSavings=" + origDefaultTimeZone.getDSTSavings());
    log.info("TimeZone.RawOffset=" + origDefaultTimeZone.getRawOffset());
    log.info("TimeZone.useDaylightTime=" + origDefaultTimeZone.useDaylightTime());

    TimeZone.setDefault(ical4jUTC);
    assertEquals(ical4jUTC, TimeZone.getDefault());
    log.info(" -- Defualt Time Zone has been changed successfully! -- ");

    TimeZone newDefaultTimeZone = TimeZone.getDefault();
    log.info("TimeZone.DisplayName=" + newDefaultTimeZone.getDisplayName());
    log.info("TimeZone.ID=" + newDefaultTimeZone.getID());
    log.info("TimeZone.DSTSavings=" + newDefaultTimeZone.getDSTSavings());
    log.info("TimeZone.RawOffset=" + newDefaultTimeZone.getRawOffset());
    log.info("TimeZone.useDaylightTime=" + newDefaultTimeZone.useDaylightTime());
}

From source file:com.ykun.commons.utils.commons.DateUtils.java

/**
 * @param date/*from  w  w  w  .j a v  a  2s.c o  m*/
 * @param pattern
 * @return
 * @throws
 * @Description:Date???
 */
public static String dateToString(Date date, String pattern) {
    return dateToString(date, pattern, TimeZone.getDefault());
}

From source file:ca.uhn.hl7v2.model.primitive.CommonTSTest.java

@BeforeClass
public static void setUpBeforeClass() {
    tz = TimeZone.getDefault();
    TimeZone.setDefault(TimeZone.getTimeZone("Canada/Eastern"));
}

From source file:gsn.charts.GsnChartJfreechart.java

public JFreeChart createChart(Collection<Data> datas) {
    TimeSeries t1 = new TimeSeries("S1");
    Iterator<Data> iter = datas.iterator();
    Data data;//w w w .  ja va2  s  . c om
    while (iter.hasNext()) {
        data = iter.next();
        t1.addOrUpdate(RegularTimePeriod.createInstance(Millisecond.class, new Date((Long) data.getP2()),
                TimeZone.getDefault()), data.getValue());
    }
    XYDataset dataset = new TimeSeriesCollection(t1);
    JFreeChart chart = ChartFactory.createTimeSeriesChart(null, null, null, dataset, false, false, false);
    chart.setAntiAlias(true);
    chart.setTextAntiAlias(true);
    chart.setBackgroundPaint(Color.WHITE);
    //
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setNoDataMessage("No Data to Display");
    plot.setDomainGridlinesVisible(true);
    plot.setBackgroundPaint(Color.WHITE);
    plot.setInsets(new RectangleInsets(5, 14, 0, 5));
    //
    DateAxis axis = (DateAxis) plot.getDomainAxis();
    axis.setDateFormatOverride(ssdf);
    axis.setTickLabelFont(TICK_FONT);
    ValueAxis rangeAxis = plot.getRangeAxis();
    rangeAxis.setTickLabelFont(TICK_FONT);
    //
    return chart;
}

From source file:com.sshdemo.common.schedule.generate.quartz.EwcmsCronTriggerBean.java

@Override
public void afterPropertiesSet() throws Exception {
    if (startDelay > 0L)
        setStartTime(new Date(System.currentTimeMillis() + startDelay));
    if (getName() == null)
        setName(beanName);/*from   w w  w  .j  a va2 s.  c o m*/
    if (getGroup() == null)
        setGroup("DEFAULT");
    if (getStartTime() == null)
        setStartTime(new Date());
    if (getTimeZone() == null)
        setTimeZone(TimeZone.getDefault());
    if (jobDetail != null) {
        setJobKey(jobDetail.getKey());
        //setJobName(jobDetail.getName());
        //setJobGroup(jobDetail.getGroup());
    }
}

From source file:com.joefernandez.irrduino.android.remote.ViewReportActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);

    setContentView(R.layout.report);/*from   w  w w .java  2s .  c  o m*/

    reportText = (TextView) findViewById(id.report_text);
    reportText.setMovementMethod(new ScrollingMovementMethod());
    settingsChanged = true;

    // get settings
    settings = PreferenceManager.getDefaultSharedPreferences(this);

    // set time zone settings and date formatter
    priorDate.setTimeZone(TimeZone.getDefault());
    nextDate.setTimeZone(TimeZone.getDefault());

    dateFormat = DateFormat.getDateFormat(this); // set localized date-only format
    timeFormat = DateFormat.getTimeFormat(this); // set localized time-only format

    //send the report request
    if (settings.getString(Settings.SERVER_HOST_NAME, Settings.DEFAULT_SERVER_HOST)
            .compareTo(Settings.DEFAULT_SERVER_HOST) == 0) {
        // default setting, warn user
        reportText.setText("Report server is not set,\n specify a server in Settings.");
    } else {
        reportText.setText("Requesting report...");
        new IrrduinoServerRequestTask().execute(getReportServerUrl() + REPORT_JSON_FORMAT);
    }
}

From source file:eu.squadd.timesheets.eolas.TimeTemplate.java

public String prepareTimesheet(String[] args) {
    String response = null;//from   ww w.  ja v a 2  s. com
    try {
        String[] ym = args[0].split("/");
        month = Integer.parseInt(ym[0]);
        year = Integer.parseInt(ym[1]);

        Calendar cal = Calendar.getInstance(TimeZone.getDefault());
        cal.set(Calendar.YEAR, year);
        cal.set(Calendar.MONTH, month - 1);
        int days = cal.getActualMaximum(Calendar.DAY_OF_MONTH);
        monthName = cal.getDisplayName(Calendar.MONTH, Calendar.SHORT_FORMAT, Locale.ENGLISH);
        String periodName = monthName + "-" + year;
        cal.set(Calendar.DATE, 1);
        String dayOfWeek = new SimpleDateFormat("EE").format(cal.getTime());

        System.out.println("Month: " + periodName);
        System.out.println("Days in month: " + days);
        System.out.println("Month starts in: " + dayOfWeek);

        Map<String, String> bankHolidays = year == 2016 ? publicHolidays2016 : publicHolidays2017;
        Map<String, String> holidays = this.extractHolidays(args);

        HSSFWorkbook wb = new HSSFWorkbook(new FileInputStream(template));
        HSSFSheet sheet = wb.getSheet("timesheet"); //getSheetAt(0);
        HSSFRow currentRow;
        SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
        FormulaEvaluator evaluator = wb.getCreationHelper().createFormulaEvaluator();
        sheet.getRow(4).getCell(1).setCellValue(periodName);
        int row = 7;
        int startRow = 0;
        int i = 1;
        while (i <= days) {
            currentRow = sheet.getRow(row);
            if (currentRow.getRowNum() > 47)
                break;
            String day = currentRow.getCell(0).getStringCellValue();

            if (day.startsWith("Total")) {
                evaluator.evaluateFormulaCell(currentRow.getCell(2));
                evaluator.evaluateFormulaCell(currentRow.getCell(4));
                row++;
                continue;
            }

            if (startRow == 0) {
                if (dayOfWeek.equals(day.substring(0, 3))) {
                    startRow = currentRow.getRowNum();
                    System.out.println("Starting row found: " + startRow + 1);
                } else {
                    row++;
                    continue;
                }
            }
            cal.set(Calendar.DATE, i);
            String date = sdf.format(cal.getTime());
            if (!day.equals("Saturday") && !day.equals("Sunday") && bankHolidays.get(date) == null
                    && holidays.get(date) == null) {
                currentRow.getCell(1).setCellValue(date);
                currentRow.getCell(2).setCellValue(defaultHours); // regular hours
                //currentRow.getCell(3).setCellValue(defaultHours);   // overtime hours
                currentRow.getCell(4).setCellValue(defaultHours); // total hours                    
            }
            i++;
            row++;
        }
        currentRow = sheet.getRow(46);
        evaluator.evaluateFormulaCell(currentRow.getCell(2));
        evaluator.evaluateFormulaCell(currentRow.getCell(4));
        currentRow = sheet.getRow(47);
        evaluator.evaluateFormulaCell(currentRow.getCell(2));
        evaluator.evaluateFormulaCell(currentRow.getCell(4));
        response = outFilePath.replace("#MONTH#", periodName);
        wb.write(new FileOutputStream(response));

    } catch (IOException ex) {
        Logger.getLogger(Timesheets.class.getName()).log(Level.SEVERE, null, ex);
    }
    System.out.println("Timesheet created.");
    return response;
}

From source file:com.haulmont.cuba.core.sys.querymacro.DateEqualsMacroHandler.java

@Override
public Map<String, Object> getParams() {
    Map<String, Object> params = new HashMap<>();
    for (MacroArgs macroArgs : paramNames) {
        TimeZone timeZone = macroArgs.timeZone == null ? TimeZone.getDefault() : macroArgs.timeZone;
        Date date1 = (Date) namedParameters.get(macroArgs.firstParamName);
        if (date1 == null) {
            throw new RuntimeException(
                    String.format("Parameter %s not found for macro", macroArgs.firstParamName));
        }/*from   www.j  a  va2 s . c o  m*/
        Calendar calendar1 = Calendar.getInstance(timeZone);
        calendar1.setTime(date1);
        calendar1 = DateUtils.truncate(calendar1, Calendar.DAY_OF_MONTH);

        Calendar calendar2 = Calendar.getInstance(timeZone);
        calendar2.setTime(calendar1.getTime());
        calendar2.add(Calendar.DAY_OF_MONTH, 1);

        params.put(macroArgs.firstParamName, calendar1.getTime());
        params.put(macroArgs.secondParamName, calendar2.getTime());
    }
    return params;
}