Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

211
Visualizações
Convert java datetime symbols to javascript libaries datetime symbols

My backend is built using java and the user settings API returns datetime formats to use within the view using Java standards (datetimes are later returned in ISO8601 and formatted on the fly). Example in Java 'yyyy-MM-dd' should be converted to 'YYYY-MM-DD' to be used with javascript's library momentjs.

Is there a direct way to convert symbols from java to javascript libraries (momentjs or date-fns)?

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

momentjs has its own specific format symbols which was confusing, whereas other libraries like date-fns are following the LDML standard. I ended up using date-fns as Java is having the same standard.

https://date-fns.org/v2.26.0/docs/Unicode-Tokens

https://www.unicode.org/reports/tr35/tr35-dates.html#Date_Field_Symbol_Table

about 4 years ago · Juan Pablo Isaza Relatório

0

This will be a pretty hand-held operation. Also you may not be able to cover all cases, but certainly the most common ones. The following should get you started.

function replacer(match, offset, string) {
  switch (match) {
    case 'M': return 'M';
    case 'MM': return 'MM';
    case 'MMM': return 'MMM';
    case 'MMMM': return 'MMMM';
    case 'd': return 'D';
    case 'dd': return 'DD';
    case 'D': return 'DDD';
    case 'DDD': return 'DDDD';
    case 'yy': return 'YY';
    case 'yyyy': return 'YYYY';
    default: return '(not supported)';
  }
}

var javaPattern = 'yyyy-MM-dd';
var regEx = /([a-z]+)/g;
var javaScriptPattern = javaPattern.replace(regEx, replacer);
console.log(javaScriptPattern);

Please go through the Java pattern letters and the JavaScript pattern letters in the two links below and expand the translations in my code as needed.

Links

  • Java format pattern letters are in the documetnation of DateTimeFormatter
  • momentjs format pattern letters are in Format - momentjs.com
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda