2010-04-08 12 views
5

वहाँ एक रास्ता समय विभाजक प्रतीक प्राप्त करने के लिए है ''? क्या यह कहीं स्थिर या गेटर है? शायद फाइल.सेपरेटर के बराबर कुछ है?जावा में समय विभाजक प्रतीक कैसे प्राप्त करें? जावा में:

मेरा समय स्ट्रिंग द्वारा DateFormat.getTimeInstance(DateFormat.SHORT, locale).format(date);

दिया जाता है यह सिर्फ प्रयोग सुरक्षित है: जब बाद में किसी को इस स्ट्रिंग पार्स करना चाहता है इस मामले में ''?

उत्तर

6

मुझे लगता है कि यह ':' उपयोग करने के लिए सुरक्षित है। यह SimpleDateFormat में हार्डकोड किया गया है। उदाहरण के लिए:

if (text.charAt(++pos.index) != ':') 
2

प्रयास करें निम्नलिखित

public static String getTimeSeparator(Locale locale) { 
    String sepValue = ":"; 

    DateFormat dateFormatter = DateFormat.getTimeInstance(DateFormat.SHORT, 
       locale); 
    DateFormatSymbols dfs = new DateFormatSymbols(locale); 
    Date now = new Date(); 

    String[] amPmStrings = dfs.getAmPmStrings(); 
    String localeTime = dateFormatter.format(now); 
    //remove the am pm string if they exist 
    for (int i = 0; i < amPmStrings.length; i++) { 
     localeTime = localeTime.replace(dfs.getAmPmStrings()[i], ""); 
    } 

    // search for the character that isn't a digit. 
    for (int currentIndex = 0; currentIndex < localeTime.length(); currentIndex++) { 
     if (!(Character.isDigit(localeTime.charAt(currentIndex)))) 
     { 
     sepValue = localeTime.substring(currentIndex, currentIndex + 1); 
     break; 
     } 
    } 

    return sepValue; 
} 
संबंधित मुद्दे