package calcul; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; import java.util.regex.Matcher; import java.util.regex.Pattern; import javax.swing.JOptionPane; public class formatDateWriter { //** exemple de date correct 2016-01-30T16:52:51 public static boolean isCorrect(String date) { Pattern p = Pattern.compile("^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}$"); Matcher m = p.matcher(date); if(m.find()) return true; JOptionPane.showMessageDialog(null, "Le format de la date n'est pas correct.
" + "Exemple de format 2019-12-25T15:50:45"); return false; } /** * * @param libreoffice_date * @return */ public static Date DateLibreOffice(String libreoffice_date){ boolean contientHeure = false; if(libreoffice_date.contains("T")) { libreoffice_date=libreoffice_date.replace("T", " "); contientHeure=true; } SimpleDateFormat simpledateformat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); Date d = null; if(!contientHeure) simpledateformat = new SimpleDateFormat("yyyy-MM-dd"); try { d = simpledateformat.parse(libreoffice_date); }catch(ParseException e) { e.printStackTrace(); } return d; } }