Document Solutions for Excel, Java Edition | Document Solutions
Features / Worksheet / Date and Time Format for a Culture
In This Topic
    Date and Time Format for a Culture
    In This Topic

    In Java, the system date and time format is not supported. Hence, when number formats like [$-x-sysdate], [$-x-systime] are used, they are ignored. However, DsExcel Java improves this behavior by picking up Windows default date and time format whenever the system date and time format is used.

    DsExcel Java supports system date and time format for following cultures:

    For non-recognizable cultures, culture data of en-US is used.

    Refer to the following example code which displays system date and time for different cultures.

    Java
    Copy Code
    //create a new workbook
    Workbook workbook = new Workbook();
    IWorksheet sheet = workbook.getActiveSheet();
    sheet.getRange("A1").setValue("Culture \\ Format");
            
    String[] formats = new String[] { "[$-x-sysdate]dddd, mmmm dd, yyyy", "[$-x-systime]h:mm:ss AM/PM" };
    String[] cultures = new String[] { "en-US", "zh-CN", "en-GB", "ja-JP", "en-AU" };
            
    // Add headers
    for (int formatId = 0; formatId < formats.length; formatId++) {
    sheet.getRange(0, formatId + 1).setValue(formats[formatId]);
    }
            
    for (int cultureId = 0; cultureId < cultures.length; cultureId++) {
    sheet.getRange(cultureId + 1,0).setValue(cultures[cultureId]);
    }
            
    // Format date cells with different cultures
    for (int cultureId = 0; cultureId < cultures.length; cultureId++) {
    Locale lc = Locale.forLanguageTag(cultures[cultureId]);
    workbook.setCulture(lc);
    for (int formatId = 0; formatId < formats.length; formatId++) {
    IRange cell = sheet.getRange(cultureId + 1, formatId + 1);
    cell.setValue(43245.5922);
    cell.setNumberFormat(formats[formatId]);
    cell.setValue("'" + cell.getText());
    }
    }
            
    // Arrange
    sheet.getRange("A:F").getEntireColumn().autoFit();
            
    //save to an excel file
    workbook.save("SystemDateAndTimeFormat.xlsx");

    Limitation